February 5, 2012

grizz grizz
Lab Rat
6 posts

Changing size of image

 

Hi. I want to load .bmp file to QImage, add some pixels and change QImage’s size. QImage is part o a class, eg.:

  1. #include <QGraphicsView>
  2. #include <QImage>
  3.  
  4. class obraz : public QGraphicsView
  5. {
  6.     Q_OBJECT
  7. public:
  8.     explicit obraz(QWidget *parent = 0);
  9.     QImage image;
  10. };

How to change QImage size?

4 replies

February 6, 2012

KA51O KA51O
Ant Farmer
467 posts

You mean like scaling [developer.qt.nokia.com] an image ?

  1. Image.scaled(Size, Qt::KeepAspectRatio);

February 6, 2012

grizz grizz
Lab Rat
6 posts

Doesn’t work. And how to load another QImage to QImage?

February 6, 2012

koahnig koahnig
Dinosaur Breeder
2932 posts
grizz wrote:
Doesn’t work.

Did you observe that scaled returns the scaled QImage?
It is not listed in the in-place section [developer.qt.nokia.com]

grizz wrote:
And how to load another QImage to QImage?

Did you try ?:

  1. Image = Image.scaled(Size, Qt::KeepAspectRatio);

February 6, 2012

grizz grizz
Lab Rat
6 posts

Now it works. I tried something like that earlier and it didn’t work, but now I know what I made wrong. Thank you.

 
  ‹‹ Deployment problems on Mac OSX      Bug in Qt Quarterly 31 Matching Parentheses with QSyntaxHighlighter ››

You must log in to post a reply. Not a member yet? Register here!