PDA

View Full Version : Creating QImage of specified size from qpic



suneel1310
31st March 2009, 09:35
Hi all,

I have a .pic file created using QPicture. Now I want to create a QImage of that with specified size. Or, atleast it should be possible for me to display the pic with specified size.
I tried :
QImage image;
QImageReader *imageReader = new QImageReader("abc.pic");
imageReader->setScaledSize(QSize(j,j));
image = imageReader->read();

but if i draw this QImage it is not displaying anything.

spirit
31st March 2009, 09:39
try to use QPicture::load.

suneel1310
31st March 2009, 10:24
But, in QPicture::load we cant pass the size.

Is it possible to create a QImage of a pic file ??
Any idea about how to do it ??

talk2amulya
31st March 2009, 10:40
why are you using this "pic" format? this format isnt even supported by QImageReader. Either you use a format that is supported by QImageReader or you write your own image format plugin using QPictureFormatPlugin/QImageIOPlugin. The former approach is much better of course.

spirit
31st March 2009, 10:53
try this


QPicture picture;
QPainter painter;
painter.begin(&picture); // paint in picture
painter.drawEllipse(0,0, 80,70); // draw an ellipse
painter.end(); // painting done
picture.save("drawing.pic");

picture.load("drawing.pic");

QPixmap pixmap(picture.boundingRect().size());
painter.begin(&pixmap);
painter.drawPicture(0, 0, picture);
painter.end();

pixmap.save("drawing_not_scaled.png", "PNG");
pixmap = pixmap.scaled(200, 200);
pixmap.save("drawing_scaled.png", "PNG");