Results 1 to 5 of 5

Thread: QImage Resize

  1. #1
    Join Date
    Jun 2007
    Posts
    10
    Thanks
    3

    Default QImage Resize

    I've been looking through the documentation for QImage, and it seems like there is no way to set the size of the image other than through the constructor.

    Am I blind, or is this really the case?

  2. #2
    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: QImage Resize

    To resize an image one would use QImage::scaled(). If you want to crop an image, you can use QImage::copy() and assign it to the same object you copied from. Other ways to change the size of an image wouldn't make sense. If you need it and are willing to lose the image data, just assign an empty QImage (with a proper size and format set) to your image object.

  3. #3
    Join Date
    Jun 2007
    Posts
    10
    Thanks
    3

    Default Re: QImage Resize

    I just wanted to check in case I missed something. What I'm actually doing is using a Qimage within a class to display different pictures, each with an arbitrary size. I was hoping I could clear the QImage, resize it and assign a new picture to it.

    Instead I think I'll just create a new QImage each time with the correct size. I was hoping to be able to declare a single QImage on the stack instead of always using new, but it looks like I have no choice. Oh well .

    Thanks for the reply.

  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: QImage Resize

    No no no... Just assign a new picture and QImage will handle the rest.

    Qt Code:
    1. QImage img("/oldimage.png");
    2. //...
    3. img = QImage("/newimage.png");
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage Resize

    Hi,
    Use a QLabel for display your image, and use the following code for resize your image,

    Qt Code:
    1. QIcon icon;
    2. QSize size;
    3. QLabel *pixmapLbl;
    4. QLabel *pixmapLabels;
    5. QImage image(fileName);
    6. if (!image.isNull())
    7. icon.addPixmap(QPixmap::fromImage(image), QIcon::Normal, QIcon::On);
    8. this->icon = icon;
    9. this->size = QSize(110,102);
    10. QPixmap pixmap = icon.pixmap(size, QIcon::Normal, QIcon::On);
    11. pixmapLabels->setPixmap(pixmap);
    To copy to clipboard, switch view to plain text mode 


    Try this, I am sure It will help you, If you need to change the size of the picture, you just change the size of that icon ( this->size = QSize(110,102); )

    Last edited by jpn; 14th December 2007 at 08:01. Reason: missing [code] tags

Similar Threads

  1. Replies: 12
    Last Post: 7th September 2011, 16:37
  2. QGraphicsScene / QGraphicsView speed after resize
    By themolecule in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2007, 23:46
  3. Resize QWidget in QMainWindow
    By aamer4yu in forum Qt Programming
    Replies: 1
    Last Post: 8th March 2007, 12:16
  4. Custom Shape Widget (resize)
    By PiXeL16 in forum Qt Programming
    Replies: 7
    Last Post: 12th February 2007, 07:00
  5. postponing resize event
    By Honestmath in forum Qt Programming
    Replies: 11
    Last Post: 26th February 2006, 00:32

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.