PDA

View Full Version : resizing an image without interpolation



mattei
7th December 2009, 16:22
hi,

I want to display an image from an array and that's done;
now i want to zoom in and out which is quite easy with Qt with the code below:

imageLabel = new QLabel;
[...]
QImage image(IMAGE_SIZE, IMAGE_SIZE, QImage::Format_RGB32);
[...]
QRgb value;
[...]
image.setPixel(c, r, value);
[...]
imageLabel->setPixmap(QPixmap::fromImage(image));
[...]
imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());

this made a zooming feature, but when zooming many times i noticed that i didn't
get a classic mosaic effect on pixel ,when the scale factor is great i could get a rectangle area for each pixel...
Instead it seems that Qt made an interpolation between the value of two pixel to fill the space between the pixels with an interpolate color value, more special this value is not always constant and predictable when there is few pixel an a great scale factor.

My question now is of course, is there a way to get a 'simple' mosaic effect without interpolation anymore?

regards,

damien

high_flyer
7th December 2009, 17:30
try scaling the image or pixmap, instead of resizing the label.

mattei
9th December 2009, 11:57
thank you, it works by resizing the QImage with no interpolation and i get a pretty 'mosaic effect',here is the code:

// define a Qsize object which is the size of new image
QSize imageSize=QSize(3*IMAGE_SIZE,3*IMAGE_SIZE);

// Scale new image with new size
QImage scaledImage = image.scaled(imageSize, Qt::KeepAspectRatio);

// update the Pixmap label with scaled image
imageLabel->setPixmap(QPixmap::fromImage(scaledImage));

// resize the label
imageLabel->resize(imageLabel->pixmap()->size());

bye

Damien

wysota
9th December 2009, 12:10
If you scale up a bitmap image there is no way you wouldn't get interpolation. It's just laws of physics. You can't escape from Nyquist-Shannon sampling theorem...