You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, July 7th 2011, 12:03pm

Zooming with QImage

Hi,
I'm having a problem with making a zooming effect to our photo editing application for phone. Because the picture is edited application uses QImage and not QPixmap.
User should be able to zoom in by pinching and to make an effect to the whole image or only to a part of the picture when it's zoomed in.

Pinching works fine and it returns the totalScaleFactor(). User can also choose an rectangle from the image which returns the top left and bottom right corners of the selected area. Effects use these coordinates to apply them to the image.

I've tried to use .scaled() but constantly scaling ruins the quality of the image and constantly converting between QImage and QPixmap would be slow. This is what I tried:
picture = picture.scaled(gesture->totalScaleFactor()*imageWidth, gesture->totalScaleFactor()*imageHeight);

Does someone have an idea how the zooming could be done? :)

2

Monday, July 11th 2011, 10:15am

We implemented the zoom by taking a copy of a certain area and displaying that (maths done in picture.copy()). scaleFactor and centerPoint are values returned by pinch gesture.


if(scaleFactor > 0.9 && scaleFactor <1.1){
scaleFactor = 1;

paint.drawImage(QRect(0,0,imageWidth,imageHeight), picture);

}else{

zoomedImage = picture.copy(centerPoint.x()-imageWidth/(2*scaleFactor),centerPoint.y()-imageHeight/(2*scaleFactor), imageWidth/scaleFactor, imageHeight/scaleFactor);

paint.drawImage(QRect(0,0, imageWidth, imageHeight), zoomedImage);

}

Used tags

QImage, Zoom