PDA

View Full Version : Clip/crop/cut an image



greenvirag
15th November 2008, 11:02
Hi everyone!

I'm just a newbie by using image with Qt, and I have some questions.
(I didn't find the answers anywhere. Maybe here..)

So, can I manipulate an image (like .png) inside my Qt program? I don't think about composition. My goal is to clip an image, but I don't know exactly, what tool I should use. Maybe QPainter or QImage or QPicture?
What tool does support to clip an image, and save the result in an other image?
(Image: no just lines -- it is not vector-graphical, it is pixel-graphical, like a pic of butterfly..)

I think the solution is easy, just I am not prudent enough.
Thank you for your answers.

Bye,
greenvirag

wysota
15th November 2008, 11:42
Use QImage. There is QImage::copy() you can use.

greenvirag
15th November 2008, 12:34
Thank you, it works, ans it was really easy :)

So, but some questions: what is the difference between paint devices? just the goal what they will modify (e.g. pixmap, widget, image, etc)? But what about the QPicture?When is it useful?

And one more question. What is the connection between QImage, QImageWriter and QImageReader. If I have a QImage, how will it be used by QImageWriter? As I saw, there isn't any constructors for QImageWriter with QImage?

Thank you for your patience.

wysota
15th November 2008, 13:29
QPicture can be thought of as a "macro recorder" - you record a series of painting operations and then you can replay them on another device. Just like a display list in OpenGL.

QImage is a storage class for image data that is read using QImageReader and written using QImageWriter. When you construct a QImage from file, it uses QImageReader to populate itself with data. It's because you have many file formats and QImage couldn't handle them all by itself. Thanks to the image reader, we can use plugins to extend Qt with capabilities of handling alien image formats (like medical data, for instance).