首页 > 解决方案 > 如何以 Grayscale8 格式在 QImage 上绘制某些颜色?

问题描述

我想在 Format_Grayscale8 格式的 QImage 上绘画,例如:

tmpPix=QImage(2000,1000,QImage::Format_Grayscale8);

QBrush brush=QBrush(QColor(Qt::red));
painter.begin(&tmpPix);
painter.fillRect(0,0,100,100,brush);
painter.end();

brush.setColor(QColor(Qt::blue));
painter.begin(&tmpPix);
painter.fillRect(100,100,100,100,brush);
painter.end();

然后我从 QImage 中获取像素数据:

uchar* data=tmpPix.bits();
qDebug("fist byte value:%d",data[0]);

data=tmpPix.scanLine(150);
qDebug("second byte value:%d",data[150]);

第一个像素数据是 87,第二个是 39。所以 Format_Grayscale8 中的 Qt::red 是 87,Qt::blue 是 39。如何使用特定值在 QImage 上以这种格式绘制?

标签: qtqimage

解决方案


推荐阅读