PDA

View Full Version : rotate a bitmap image



saman_artorious
30th November 2013, 08:39
I do not know how to rotate bitmap BGR image of size 800 * 600 * 3 by 90 degrees. If it was an image with a header, the solution would be:


QImage srcImg(":/icon.png");
QPoint center = srcImg.rect().center();
QMatrix matrix;
matrix.translate(center.x(), center.y());
matrix.rotate(90);
QImage dstImg = srcImge.transformed(matrix);
QPixmap dstPix = QPixmap::fromImage(dstImg);


I read the whole image in a 800 * 600 * 3 image. Next, before I render it to the screen, I need to rotate it by 90 degrees.

anda_skoa
30th November 2013, 11:09
What do you mean if it were an image with a header?

Cheers,
_

saman_artorious
30th November 2013, 11:22
What do you mean if it were an image with a header?

Cheers,
_

if it is PNG or JPEG we can set it the QByteArray to a pixmap or QImage like:

image->loadFromData(bytes, "PNG");

but when it is raw data of 800 by 600 by 3, it has no header, it is not PNG or of any type anymore. I wonder how I can rotate the image by 90 degree in this case!

Cheers,

stampede
1st December 2013, 08:55
But you still know how to access the pixel(i,j), and how to display the data ? What is the pixel data layout now ?
Another thing, how do you display the data ? If you need the rotation only for display, and you are using opengl, you can rotate it by simple glRotate(...) before pixmap rendering code.

anda_skoa
1st December 2013, 09:14
but when it is raw data of 800 by 600 by 3, it has no header, it is not PNG or of any type anymore. I wonder how I can rotate the image by 90 degree in this case!


At the time when transformed() is called with the rotation matrix, there is just QImage, so it always works the same way.
QImage works on pixel data, not on whatever source format. The source format is only important for getting the pixel data into the QImage instance.
Since you are asking about the rotation step, which is after loading, I assume you have the loading covered.

So the answer to your question is: create a rotation matrix, call QImage::transformed()

Cheers,
_