Results 1 to 15 of 15

Thread: Question about QImages

  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Question about QImages

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Question about QImages

    Quote Originally Posted by SkripT
    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?

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about QImages

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Question about QImages

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about QImages

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Question about QImages

    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about QImages

    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?

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Question about QImages

    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.

  9. #9
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about QImages

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

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Question about QImages

    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.

  11. #11
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about QImages

    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?

  12. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Question about QImages

    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.

  13. #13
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about QImages

    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

  14. #14
    Join Date
    Jan 2006
    Location
    Genk, Belgium
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Question about QImages

    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

  15. #15
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about QImages

    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.

Similar Threads

  1. Useless but curious compiler warning question
    By Raccoon29 in forum General Programming
    Replies: 4
    Last Post: 30th July 2008, 21:46
  2. SQL Question
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 20:36
  3. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 18:49
  4. Replies: 1
    Last Post: 15th March 2007, 21:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.