我正在尝试在 QImage 上进行一些屏幕外渲染(没什么特别的,只是一些合成的缩略图)并且遇到了一个问题,即使是新的和应该是空白的 QImages 也有一些非常严重的噪音:
要重现的代码相当简单:
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/