Results 1 to 8 of 8

Thread: Painting an overlay on a QLabel->QImage

  1. #1
    Join Date
    Jan 2011
    Posts
    55
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Painting an overlay on a QLabel->QImage

    I've a QLabel which I use to display a reference QImage. Now, I'd like to paint over the reference image, and save only the overlay strokes as a separate QImage (thus no pixels from the reference image have to be accounted).
    Any suggestion? Thanks

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting an overlay on a QLabel->QImage

    one brute-force & not very good way is to save a copy of the original pixmap, then let user draw whatever they want on the other copy. When you want to save, compare each pixel to the backup. If the pixel value is different, save it, otherwise save a transparent/empty pixel.

    A better way would be to have enough control of the strokes and user operations that you can just copy the painter path and write them to an empty pixmap at the same time as painting them on the image.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    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: Painting an overlay on a QLabel->QImage

    hen you want to save, compare each pixel to the backup.
    You don't need to compare.
    Just have two pixmaps.
    Draw the original in to the first pixmap and show it.
    When the user draws, draw it in to the other pixmap *and* on to the original (and don't show the second pixmap), this way you can show the composite result, while having both versions separate.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting an overlay on a QLabel->QImage

    yeah, I already said that in my other paragraph.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    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: Painting an overlay on a QLabel->QImage

    Not quite:
    When you want to save, compare each pixel to the backup.
    This is not necessary.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting an overlay on a QLabel->QImage

    Quote Originally Posted by amleto View Post
    yeah, I already said that in my other paragraph.
    Quote Originally Posted by high_flyer View Post
    Not quite:
    When you want to save, compare each pixel to the backup.
    This is not necessary.
    like I said, I already said that in my other paragraph.
    Quote Originally Posted by amleto View Post
    one brute-force & not very good way is to save a copy of the original pixmap, then let user draw whatever they want on the other copy. When you want to save, compare each pixel to the backup. If the pixel value is different, save it, otherwise save a transparent/empty pixel.

    A better way would be to have enough control of the strokes and user operations that you can just copy the painter path and write them to an empty pixmap at the same time as painting them on the image.
    The second paragraph is clearly separate from the first paragraph that you keep quoting because it is a separate paragraph. I hope it is clear now. I haven't even mentioned that I started that paragraph with 'A better way' to indicate that I am talking about an alternative method. A method where I make no reference to comparisons at all.

    ... dangit!
    Last edited by amleto; 9th July 2012 at 17:52.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. #7
    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: Painting an overlay on a QLabel->QImage

    From your second paragraph one can understand (as I did) that you imply that operations should be taken to save a painter path (as in, explicitly deal with the painter path), specially when one reads your fist paragraph where you suggest comparing pixels.
    My point was that this all is not needed.
    If you didn't mean it, well, that's the way (at least) I understood it.

    And cool down man.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting an overlay on a QLabel->QImage

    I think it is rather a case of not reading what I have written. anyway...
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Replies: 8
    Last Post: 5th July 2011, 07:32
  2. Replies: 1
    Last Post: 14th July 2010, 16:34
  3. Font size calculation when painting in a QImage
    By Ishark in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2007, 22:22
  4. QLabel Painting
    By vijay anandh in forum Qt Programming
    Replies: 4
    Last Post: 15th May 2006, 13:12
  5. Trouble with image painting (QPainter + QImage)
    By krivenok in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2006, 20:25

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.