QImage与Format_Mono如何存储信息

How does QImage with Format_Mono store informations ?

本文关键字:存储 信息 何存储 Format Mono QImage      更新时间:2023-10-16

我试图从QImage复制值到我自己的图像结构(因为学校的工作),我无法弄清楚,像素是如何存储的

API说,当使用Format_Mono时,图像以每像素1位存储。

我创建了以下代码:
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 !!

第一件事:我不明白为什么使用40个字节(我预计20个就足够了-就像java中的BufferedImage一样)

第二件事:当迭代像素时,每四个字节(从第三个索引2,6,10…开始)设置为173,每四个字节(从第四个索引3,7,11…开始)设置为186。其他字节被正确地(??)设置为255(白色)。

我期望20个字节,因此19将被设置为255,而1(将彩色像素[10,1]设置为其他值)

我错过了什么?谢谢你

API:扫描线数据在32位边界上对齐。

那就是……的原因。方法bits()的Qt文档忘记提到了…