Hi there,

I want to rotate a monochrome image of Type QImage using QImage::transformed method.
After applying rotation, the background color of the void area is always black.

The Image before Rotation lookes like this:
original.gif

After rotation, of 45° clockwise, it lookes like this:
rotated.gif

But it should look like this:
rotated_correct.png

My question is how can I make sure that the void area color is white?
Thanks in advance!

Here is my sample code:

Qt Code:
  1. #include <QImage>
  2. #include <QPainter>
  3.  
  4. int main()
  5. {
  6. // size of square Image
  7. const int nSize = 100;
  8.  
  9. // create monochrome Image
  10. QImage img = QImage(nSize, nSize, QImage::QImage::Format_Mono);
  11.  
  12. QPainter pnt;
  13. pnt.begin(&img);
  14.  
  15. // fill background with white
  16. pnt.fillRect(0, 0, nSize, nSize, Qt::color0);
  17. pnt.setPen(QPen(Qt::color1));
  18. // draw a rectangle
  19. pnt.drawRect(0, 0, nSize-1, nSize-1);
  20. pnt.end();
  21.  
  22. img.save("original.bmp");
  23.  
  24. // rotate image
  25. m.rotate(45);
  26. img = img.transformed(m);
  27. img.save("rotated.bmp");
  28.  
  29. return 0;
  30. }
To copy to clipboard, switch view to plain text mode