Results 1 to 8 of 8

Thread: HELP PLEASE- Superimpose two images in a QPixmap

  1. #1
    Join Date
    Jul 2013
    Posts
    4
    Thanks
    4

    Default HELP PLEASE- Superimpose two images in a QPixmap

    Hello

    I wonder if you can assist. I'm running Qt Creator 2.7.0 based on Qt 5.0.2 using a Windows 7 Enterprise Intel Core 2 Duo E7200.

    I'm a complete Newbie so please forgive my somewhat trivial query.

    My aim is to superpose two .jpg images into a QPixmap.

    However, I have followed others' suggestions (on this board) for an identical problem, and using their suggestions, I have tried the following code:




    Qt Code:
    1. //....................................................................................................................................
    2.  
    3. // LOAD IMAGE
    4. if (!fileName.isEmpty()) {
    5. QImage image(fileName);
    6. if (image.isNull()) {
    7. QMessageBox::information(this, tr("Mammogram Viewer"),
    8. tr("Cannot load %1.").arg(fileName));
    9. return;
    10. }
    11.  
    12. //....................................................................................................................................
    13. QImage BottomMammogram(fileName);
    14. BottomMammogram= BottomMammogram.convertToFormat(QImage::Format_ARGB32);
    15. image.fill(qRgba(0,0,0,0));
    16.  
    17. QImage TopMammogram("C:/TopMammogram");
    18. TopMammogram= TopMammogram.convertToFormat(QImage::Format_ARGB32);
    19. image.fill(qRgba(0,0,0,0));
    20.  
    21. painter1 = new QPainter;
    22. img = new QPixmap(500, 500);
    23.  
    24. painter1->begin(img);
    25. painter1->fillRect(img->rect(), Qt::transparent);
    26. painter1->drawImage(0, 0, BottomMammogram); // puts BottomMammogram image into img
    27. painter1->drawImage(50, 50, TopMammogram); // puts TopMammogram image into img
    28. painter1->end();
    29.  
    30. imageLabel->setPixmap(*img);
    31. imageLabel->show();
    To copy to clipboard, switch view to plain text mode 



    I have had no success with the above code, since the top Picture is completely opaque.

    Any help would be gratefully appreciated.

    Thank you in advance.


    NotQuiteFeynman

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: HELP PLEASE- Superimpose two images in a QPixmap

    If you are drawing an opaque image over another opaque image, why do you expect to receive something else than an opaque image drawn over another image?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    NoQuiteFeynman (30th August 2013)

  4. #3
    Join Date
    Jul 2013
    Posts
    4
    Thanks
    4

    Default Re: HELP PLEASE- Superimpose two images in a QPixmap

    Hello

    Thank you for the reply - it's much appreciated.

    Sorry if I'm being daft, but doesn't 255 specify no opacity? Please see:

    http://www.qtcentre.org/threads/1307...Qt-transparent

    Your further advice would be much appreciated.

    Kindest regards

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: HELP PLEASE- Superimpose two images in a QPixmap

    Quote Originally Posted by NoQuiteFeynman View Post
    Hello

    Thank you for the reply - it's much appreciated.

    Sorry if I'm being daft, but doesn't 255 specify no opacity? Please see:

    http://www.qtcentre.org/threads/1307...Qt-transparent
    I don't see any "255" in your code. Could you elaborate what you mean?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    NoQuiteFeynman (30th August 2013)

  7. #5
    Join Date
    Jul 2013
    Posts
    4
    Thanks
    4

    Default Re: HELP PLEASE- Superimpose two images in a QPixmap

    Hi

    Thanks for the continuing responses.

    I thought you meant that I need to use image.fill(qRgba(0,0,0,255)); for transparency! Other advice on the board says I need to use image.fill(qRgba(0,0,0,0)); for transparency.

    Should I use something else for transparency?

    Please advise.

    Kindest regards

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: HELP PLEASE- Superimpose two images in a QPixmap

    Quote Originally Posted by NoQuiteFeynman View Post
    Should I use something else for transparency?
    A transparent image that you render on the pixmap (be it transparent or not). I don't know what sizes your jpeg images have but assuming their size is somewhere close to 500x500, they will most probably cover the whole area of the pixmap so it doesn't matter if you "fill the pixmap with transparency" or not if you then draw a non-transparent image over it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    NoQuiteFeynman (30th August 2013)

  10. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: HELP PLEASE- Superimpose two images in a QPixmap

    Zero in the alpha channel makes a pixel totally transparent, and 1.0 (255 when expressed as 8 bit int) makes it totally opaque.

    I gather you want a partly transparent top image to be drawn over the bottom image.

    Qt Code:
    1. QImage top("top.jpg");
    2. QImage bot("bottom.jpg");
    3. // both images are opaque because JPEG has no alpha channel
    4.  
    5. QPixmap combined(bot.size());
    6. QPainter p(&combined);
    7. p.drawImage(QPoint(0, 0), bot); // drawn as-is
    8. p.setOpacity(0.2);
    9. p.drawImage(QPoint(0, 0), top); // drawn at 20% opacity
    10. p.end();
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to ChrisW67 for this useful post:

    NoQuiteFeynman (30th August 2013)

  12. #8
    Join Date
    Jul 2013
    Posts
    4
    Thanks
    4

    Default Re: HELP PLEASE- Superimpose two images in a QPixmap

    Hi

    This works, thank you very much for your help ChrisW67 and Wysota, it's very much appreciated!

    All the best.

    Kindest regards

Similar Threads

  1. QPixMap doesn't show one of two images !
    By ladiesfinger in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2011, 16:29
  2. Replies: 4
    Last Post: 28th August 2008, 13:13
  3. Replies: 1
    Last Post: 21st August 2008, 07:44
  4. Replies: 5
    Last Post: 9th April 2007, 14:26
  5. [QT3] QToolTip with Images (QPixMap) ?
    By BrainB0ne in forum Qt Programming
    Replies: 4
    Last Post: 27th January 2006, 08:31

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
  •  
Qt is a trademark of The Qt Company.