indira
indira

Reputation: 6687

How to draw picture on a QPainter by reading the data from a byte array in Qt?

I have a byte (unsigned char) array. How to draw it using QPainter?

Upvotes: 3

Views: 1365

Answers (2)

neciu
neciu

Reputation: 4485

QImage docs says:

[...]data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned. [...]

so maybe you'll prepare your data for that?

Just make new array four time bigger than original one and fill R, B, G with your value and A with 255. Then pass this new array to QImage constructor and that's all.

Upvotes: 0

shofee
shofee

Reputation: 2129

You can use QImage instead, and pass your byte (unsigned char) array to the constructor of QImage. See http://developer.qt.nokia.com/doc/qt-4.8/qimage.html#QImage-4

Upvotes: 3

Related Questions