1 Attachment(s)
Need help simplifying the logic of an image editor program
I am creating an image editor where I perform pixel manipulations to a QImage object, and use a QPixmap (displayed through a QLabel) to represent the changes made to the QImage. The reason why I am using two separate objects for the image is that the QLabel is resizable (to offer the user a better view), and hence, the QPixmap may not be the exact representation of the image. For a better explanation of the relationship between the objects, see the following diagram:
Attachment 11994
Therefore, this is what is happening in my program:
- The user performs mouse movements over the QLabel, in order to edit the image.
- The x, y coordinates of the mouse events are used to determine the particular pixel of the QPixmap (the resized image).
- The pixel's x, y values and the resize factor of the QPixmap are used to determine the target pixel of the QImage.
- The target pixel is modified.
- A new QPixmap is created from the modified QImage, which is then used to replace the old one.
As you can probably guess, this design is pretty slow. It won't be a big issue for smaller images, but for larger images I need to speed things up. How do I do it? How do programs like Photoshop achieve this?
Re: Need help simplifying the logic of an image editor program
You could do without the QPixmap if you subclass QLabel and override the paintEvent. You'ld probably need to keep track of your transform but that shouldn't be a problem.