PDA

View Full Version : Question about QImages

SkripT
20th January 2006, 15:27
Hi all. As I have comented in another thread, I am programming a simple photo editor that supports zooming, rotation and selection of rectangular parts of the image to cut or paint them. Well, by now I have the original image in a QImage and I paint it with qPainter (drawImage) and all goes ok. When I change the zoom of the image what I do is simply call the method "scale" of qpainter and draw the image. The problem doing it in this way is that if the user wants to select a part of the image, the coordenates of the selection are respect the scaled image and if I traspose this coordinates at the original image, could appear some error. I've seen that with simple photo editor programs like Paint of Windows if I zoom the image, I can modifiy the zoomed image and never appear any error. I think that's because when the user modify the scale of the image, the size of the orginal image is modified, not only when the image is painted (as I am making it now). But I think that, If everytime that the user zooms an image, the original image is resized could appear loss of information. So I don't know if there's another way to do it. Anyone could explain how could I solve the problem? Thanks.

zlatko
20th January 2006, 15:51
The problem doing it in this way is that if the user wants to select a part of the image, the coordenates of the selection are respect the scaled image and if I traspose this coordinates at the original image, could appear some error..

1) how do you transpose scaled coordinates to the coordinates of original image?
2) actually what kind of errors you mean?

SkripT
20th January 2006, 16:01
1) how do you transpose scaled coordinates to the coordinates of original image?

Well I have a variable "double scaleFactor" with the result of: size of the scaled image / size of the original image. When I have the coordinates of the scaled images, I calcule the coordinates at the original image with: (x, y) = (x' / scaleFactor, y' / scaleFactor) where x' and y' are the coordinates in the scaled image.

2) actually what kind of errors you mean?

Errors of precition with the operation above.

high_flyer
20th January 2006, 16:17
there is no way to avoid information loss when scaling down.
It would be better if you use the QImage scaling and not do it your self.
When you zoom in an image, and edit, dont edit the original, but the zoomed image, and then scale it down to original when saving, this way QImage will do the work for you.

SkripT
20th January 2006, 16:27
Sorry I don't understand what you want to say. When the user zooms an image this don't means change the size of the original image, only of the image that I show on the screen. But if the user modifies this zoomed image, this operation has to be done under the original image and not on the scaled image. As I think

high_flyer
20th January 2006, 17:41
When the user zooms an image this don't means change the size of the original image
Exactly.
Thats why:

dont edit the original, but the zoomed image, and then scale it down to original when saving

In simple words: alwas edit what you see.

SkripT
20th January 2006, 18:16
So in your opinion, in case that the user selects a rectangular part of the image, once some zoom is aplied, to be painted of another color, this painting has to be done from the image scaled or from the original image?

high_flyer
20th January 2006, 18:49
yes,on the zoomed image.
If you are implementing it so, that the user only sees the zoomed area and not a zoom image in a scrolled area, then you will have to remeber the zoomed rectangle coordinates on the original image, so that you "paste" there the edited zoomed area when the user returns to the original image view.
If on the other side you let the image be zoomed and apply scroll bars, then you dont need to remember any thing, just scale the zommed (edited) image back.

SkripT
20th January 2006, 19:05
Sorry but in the case of the scroll bars, the changes on the edited image in which moment are "updated" at the original image?

high_flyer
20th January 2006, 19:14
if you use the scroll bar option you dont need two images, only one, the one that you see, in the size it is at the moment, so when you edit it you are editing the image it self, no need to remember anything aside the original size.

SkripT
20th January 2006, 19:43
Well so here's the question that i make at the beginning of the thread: if you work only with the edited image and you apply recursive zooming to the image, it will lose quality, won't it?

high_flyer
20th January 2006, 21:38
yes it will as I said, you can't put the same amount of information in less "space".
When you scale down you loos information.

I thought your question was about the error you get from calculating your self the scaling, and my point was that you dont need to do it your self, but can let Qt do it for you.

SkripT
21st January 2006, 23:52
Hi, finally I have solved the problem. It's a little complicated to explain; in a little words the problem was that I was scaling at any "ratio" while all the other editors scale in order of 1/2, 1/3, 1/4, 1/5, .. Doing it in this way solves the problem of loss of precition. Thanks high_flyer

Pieter from Belgium
27th January 2006, 09:15
If you keep the original image, and paint it scaled when zooming, keep track of the viewing transformation and use the inverse transformation to paint _in the original image_, loss of information is avoided, regardless of the zoom factor. The zoom factor will only determine the quality/amount of information of the displayed image, not of the original one.

If the size of the images is not too large, and only modest zoomlevels up to something like 200% are needed, using QCanvasView (Qt3) might be a good idea. (No idea about Qt4.)

Pieter

SkripT
27th January 2006, 12:45
Hi Peter, the problem is that the mouse coordinates are from the scaled image, so they has to be translated to the original image with no less of precition. That's why not every scale could be correct.