Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 如何在QImage上以Grayscale8格式绘制特定颜色?_Qt_Qimage - Fatal编程技术网

Qt 如何在QImage上以Grayscale8格式绘制特定颜色?

Qt 如何在QImage上以Grayscale8格式绘制特定颜色?,qt,qimage,Qt,Qimage,我想在QImage上以灰度8格式绘制,如: 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(&tmp

我想在QImage上以灰度8格式绘制,如:

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。所以Qt::red的格式是87,Qt::blue的格式是39。我如何使用特定的值在QImage上以这种格式绘制?

或者Qt如何将rbga颜色转换为灰度颜色?我想我只需要将画笔或笔的颜色设置为特定的灰色,灰度图像中像素的数据将是我想要的特定数字。或者Qt如何将rbga颜色转换为灰度颜色?我想我只需要将画笔或笔的颜色设置为特定的灰度颜色,灰度图像中像素的数据将是我想要的特定数字。