Question

We are currently using a commercial library for image rendering with Windows. When displaying monochrome images in sizes smaller than the images original size, this library gray scales images so that still most of them can be recognized:

enter image description here

Now i tried the same with a Qt 4.8 Application. Basically whats done is calling:

QImage mImage;
...
mImage.load(...);
...
painter.drawImage(paintRect, mImage, mImage.rect()); 

Where paintRect is smaller than mImage.rect(). That works well, but the output is much less satisfying:

enter image description here

I tried several renderHints (QPainter::SmoothPixmapTransform, Antialiasing, HighQualityAntialiasing) and also converted the Image using

mImage = mImage.convertToFormat(QImage::Format_RGB32);

QPainter::SmoothPixmapTransform seemed to improve the output a little bit (its included in the screen shot). All the other things do not seem to change anything.

Am i missing something?

How can display of images with decrease size be improved?

Était-ce utile?

La solution

It is possible that during

painter.drawImage(paintRect, mImage, mImage.rect()); 

the painter just interpolate which pixel to take in the initial image when the size differs. Which will explain the second image.

Scale manual using

QImage todraw = mImage.scaled(
            paintRect.size(),
            Qt::IgnoreAspectRatio,
            Qt::SmoothTransformation);
...
painter.drawImage(paintRect, todraw, mImage.rect()); 

You compute the image todraw only on resize events (to avoid scaling every paint event) and you use it instead with the painter.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top