0

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

4

1 回答 1

1

为了获得可靠的行为,您应该在访问原始图像数据之前检查 的返回值QImage::format()以查看使用的基础格式。

Qt 似乎更喜欢真彩色的RGB32/ARGB32格式,其中每个像素占用 4 个字节,无论是否存在 alpha 通道(对于RGB32格式,它只是用 填充0xff)。如果您加载真彩色图像,它可能是这两种格式之一。

此外,字节顺序可能因平台而异,QRgb尽可能用于访问 32 位像素。

顺便说一句,扫描线不应该是水平的吗?我认为您应该使用width()而不是height()计算扫描线的长度。

于 2011-12-03T03:48:08.377 回答