Results 1 to 4 of 4

Thread: resizing an image without interpolation

  1. #1
    Join Date
    Dec 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default resizing an image without interpolation

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: resizing an image without interpolation

    try scaling the image or pixmap, instead of resizing the label.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Dec 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: resizing an image without interpolation

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: resizing an image without interpolation

    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...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Image Commander v.1.2
    By piotrek in forum Qt-based Software
    Replies: 0
    Last Post: 20th April 2009, 10:59
  2. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 15:36
  3. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  4. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  5. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.