scanline function in qimage class

3k Views Asked by At

I'm developing application for editing raster graphic. In this application I have to create scanline function which will do same thing as scanline function in QImage class. But I'm little confused with the way that scanline function works and with scanline generally. For example, when I call bytesPerLine() for image which height is 177px I was expecting that value will be 531 (3 bytes for each pixel) but this function is returning 520?

Also, when I use uchar data = image->scanLine(y)[x] for R=249 G=249 B=249 value in variable data is 255. I really don't understand this value. Thanks in advance :)

1

There are 1 best solutions below

0
On

For reliable behavior you should check the return value of QImage::format() to see what underlying format is used before accessing the raw image data.

Qt seems to prefer RGB32/ARGB32 format for true-colors, where each pixel takes 4 bytes, whether an alpha channel exists or not (for RGB32 format it's simply filled with 0xff). If you load a true-color image, it's probably in one of these two formats.

Besides, the byte order can be different across platforms, use QRgb to access 32-bit pixels whenever possible.

BTW, shouldn't a scanline be horizontal? I think you should use width() instead of height() to calculate the length of a scanline.