qt - 如何以 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 上以这种格式绘制?
解决方案
推荐阅读
- android - Hilt Android 中的多网络模块
- python - 熊猫数据框日期时间排序返回错误的时间值
- snowflake-cloud-data-platform - 将默认值分配给 TIMESTAMP_NTZ 雪花
- spring-boot - 如何在外部化 jpa 本机查询中指定命名参数
- python - 遍历每个 XML 文件
- android - android概览按钮/最近按钮/最近列表/多个应用列表,显示活动屏幕黑色/空白/清除
- html - Angular Material 类 mat-app-background 与 position:fixed
- javascript - 倒计时后如何使弹出窗口保持不变?
- json - Newtonsoft.Json.6.0.8 与 Newtonsoft.Json.12.0.3 的反序列化差异
- python - 无法播放音乐pygame win 10