【问题标题】:How does QImage with Format_Mono store informations ?带有 Format_Mono 的 QImage 如何存储信息?
【发布时间】:2013-05-19 21:26:46
【问题描述】:

我正在尝试将值从 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,一个(彩色像素 [10,1] 设置为其他值)

我错过了什么?谢谢

【问题讨论】:

    标签: c++ qt qimage


    【解决方案1】:

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

    这就是原因......方法 bits() 的 Qt 文档忘记提及它......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-07
      • 1970-01-01
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 2017-03-08
      • 1970-01-01
      相关资源
      最近更新 更多