PDA

View Full Version : QImage Resize



stealth86
7th December 2007, 23:59
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?

wysota
8th December 2007, 00:12
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.

stealth86
8th December 2007, 00:35
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.

wysota
8th December 2007, 12:59
No no no... Just assign a new picture and QImage will handle the rest.


QImage img("/oldimage.png");
//...
img = QImage("/newimage.png");

sabeesh
14th December 2007, 04:11
Hi,
Use a QLabel for display your image, and use the following code for resize your image,


QIcon icon;
QSize size;
QLabel *pixmapLbl;
QLabel *pixmapLabels;
QImage image(fileName);
if (!image.isNull())
icon.addPixmap(QPixmap::fromImage(image), QIcon::Normal, QIcon::On);
this->icon = icon;
this->size = QSize(110,102);
QPixmap pixmap = icon.pixmap(size, QIcon::Normal, QIcon::On);
pixmapLabels->setPixmap(pixmap);


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); )

:)