Qpainter显示QImage不正确,显示为灰色,求大神教育

panrou3390 2016-07-29 08:29:38
我用qPainter在qlabel上显示Qimage,如果是QImage image(filePath),直接通过图片文件新建QImage的话,显示是正确的,如果用如下的方式,则显示为灰色,但是我如下设置的rgb值不是灰色的,请问各位大神,我这是哪里出错了吗?
uchar*imageBuf = new uchar[1024 * 1024 * 4];
for (int i = 0; i < 1024; i++)
{
imageBuf[4 * i] = 144;
imageBuf[4* i+1] = 98;
imageBuf[4 * i+2] = 74;
imageBuf[4 * i+3] = 0;
}
QImage image(imageBuf, 1024, 1024,1024*4, QImage::Format_RGBA8888);
QPainter painter(this);
QRectF target(0,0,400,400);
QRectF source(0,0,1000,1000);
painter.drawImage(target, image, source);
...全文
872 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
冷静忍耐 2016-07-31
  • 打赏
  • 举报
回复
觉得你可以直接写死一个颜色看有没有问题
东莞某某某 2016-07-30
  • 打赏
  • 举报
回复
imageBuf中的数据配置错了吧。 简单地指定图片颜色,你可以直接用QImage::fill()
dext 2016-07-29
  • 打赏
  • 举报
回复
我不知道你这是什么颜色?因为不知道你的alpha 到底是 0 还是 144 The image is stored using a 32-bit byte-ordered RGBA format (8-8-8-8). Unlike ARGB32 this is a byte-ordered format, which means the 32bit encoding differs between big endian and little endian architectures, being respectively (0xRRGGBBAA) and (0xAABBGGRR). The order of the colors is the same on any architecture if read as bytes 0xRR,0xGG,0xBB,0xAA.

16,154

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧