Sam
Sam

Reputation: 873

how to rotate a bitmap image

I receive 800 by 600 by 3 bitmap image and give as a parameter to glDrawPixels(). Before giving this to glDrawPixels, I want to rotate the bitmap by 90 degrees. is that possible?

in case it was not a bitmap and instead an image like png, I would do the following:

QMatrix rm;

rm.rotate(90);

pixmap = pixmap.transformed(rm);

pixmap.scaled(801, 701);

texture = bindTexture(pixmap);

Upvotes: 3

Views: 8454

Answers (2)

cmannett85
cmannett85

Reputation: 22346

As answered by liuyi.luo, the normal way of doing this is by using QImage and passing in the raw data with the required format, before transforming.

Unfortunately Qt does not support BGR channel order. You will have to find a third-party library, or roll your own algorithm - which should be pretty trivial if you are rotating by 90degs. Here's a decent implementation of in-place rotation.

Upvotes: 1

liuyi.luo
liuyi.luo

Reputation: 1229

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);

Upvotes: 11

Related Questions