2
votes

i'm trying to copy values from QImage to my own image structure (because of school work), and I'am not able to figure out, how are pixels stored

API says that when using Format_Mono, The image is stored using 1-bit per pixel.

I created the following code:

QImage image(10,10,QImage::Format_Mono); // create 10x10 image
image.fill(1); // whiten the image
QPainter p;
p.begin(&image);
p.setPen(QPen(QColor(Qt::black)));
p.drawPoint(10,1); // make ONE point black
p.end();
uchar* pixels = image.constBits();
int count = image.byteCount(); // returns 40 !!

First thing: I don't understand why 40 bytes is used (I expected 20 will be more than enough - as would BufferedImage in java do)

Second thing: When iterating throuh pixels, every fourth(starting on third - indexes 2,6,10...) byte is set to 173 and every fourth(starting on fourth - indexes 3,7,11...) byte is set to 186. Other bytes are correctly(??) set to 255 (white).

I expected 20 bytes, so 19 would be set 255, and one (with colored pixel [10,1] set to other value)

What am I missig? Thank you

1

1 Answers

3
votes

API: The scanline data is aligned on a 32-bit boundary.

That was the reason ... the Qt documentation of the method bits() forgot to mention it...