Qt:空透明QImage有噪音

标签 qt qimage jambi

我正在尝试在 QImage 上进行一些屏幕外渲染(没什么特别的,只是一些合成的缩略图)并且遇到了一个问题,即使是新的和应该是空白的 QImages 也有一些非常严重的噪音:

screenshot

要重现的代码相当简单:

QImage image = new QImage(
        (int) b.width(), (int) b.height(),
        QImage.Format.Format_ARGB32);
painter.drawImage(0, 0, image);

(b 只是一个 QRectF,包含我正在绘制的 QGraphicsItem 的边界)

填充新图片好像没有什么效果:

QPainter p = new QPainter(image);
p.fillRect(b, QColor.transparent);
p.end();

用任何纯色(例如白色)填充它可以消除噪音,但不幸的是我需要这个特定的图像是透明的。有什么办法可以消除噪音吗?

我使用的是 Qt Jambi (4.7.1-beta),但我认为这不会产生很大的不同。

最佳答案

来自 QImage::QImage(int width, int height, Format format) 的文档:

Warning: This will create a QImage with uninitialized data. Call fill() to fill the image with an appropriate pixel value before drawing onto it with QPainter.

因此在构建图像后调用QImage::fill(uint pixelValue)

关于Qt:空透明QImage有噪音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13464627/

相关文章:

qt - 如何在 Windows 中为 Qt 应用程序生成良好的崩溃日志报告

c++ - 关于qt读取文件内容

qt - 如何从 C++ 端多次将 QImage 对象设置为 QML 的 Image 元素?

qt - 使用 QImage 和 OpenCV 显示图像

java - 连接 QPushButton Jambi

c++ - 使用 C++ 解析 HTML(最好使用 Qt)

Qt QString maxsplit 参数

c++ - QImage::fill(Qt::red) 总是黑色?

c# - 现代图形用户界面开发