Question

I'm trying to do some offscreen rendering onto a QImage (nothing special, just a few composited thumbnails) and am running into an issue where even new and supposedly blank QImages have some pretty serious noise:

screenshot

The code to reproduce is fairly simple:

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

(b is just a QRectF containing the bounds of the QGraphicsItem I'm painting onto)

Filling the new image doesn't seem to have any effect:

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

Filling it with any solid color (e.g. white) removes the noise, but unfortunately I need this particular image to be transparent. Is there some way to remove the noise?

I'm using Qt Jambi (4.7.1-beta) though I don't think that should make a huge difference.

Was it helpful?

Solution

From the docs for 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.

So call QImage::fill(uint pixelValue) on your image after constructing it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top