KBA
16th November 2017, 16:23
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:
12674
After rotation, of 45° clockwise, it lookes like this:
12675
But it should look like this:
12676
My question is how can I make sure that the void area color is white?
Thanks in advance!
Here is my sample code:
#include <QImage>
#include <QPainter>
int main()
{
// size of square Image
const int nSize = 100;
// create monochrome Image
QImage img = QImage(nSize, nSize, QImage::QImage::Format_Mono);
QPainter pnt;
pnt.begin(&img);
// fill background with white
pnt.fillRect(0, 0, nSize, nSize, Qt::color0);
pnt.setPen(QPen(Qt::color1));
// draw a rectangle
pnt.drawRect(0, 0, nSize-1, nSize-1);
pnt.end();
img.save("original.bmp");
// rotate image
QMatrix m;
m.rotate(45);
img = img.transformed(m);
img.save("rotated.bmp");
return 0;
}
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:
12674
After rotation, of 45° clockwise, it lookes like this:
12675
But it should look like this:
12676
My question is how can I make sure that the void area color is white?
Thanks in advance!
Here is my sample code:
#include <QImage>
#include <QPainter>
int main()
{
// size of square Image
const int nSize = 100;
// create monochrome Image
QImage img = QImage(nSize, nSize, QImage::QImage::Format_Mono);
QPainter pnt;
pnt.begin(&img);
// fill background with white
pnt.fillRect(0, 0, nSize, nSize, Qt::color0);
pnt.setPen(QPen(Qt::color1));
// draw a rectangle
pnt.drawRect(0, 0, nSize-1, nSize-1);
pnt.end();
img.save("original.bmp");
// rotate image
QMatrix m;
m.rotate(45);
img = img.transformed(m);
img.save("rotated.bmp");
return 0;
}