Results 1 to 4 of 4

Thread: How do I join two QImages to form one Image

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How do I join two QImages to form one Image

    Small issue, I have an image which I split into two images using the QImage::copy() function. I then did some custom painting on each piece of the image and now I want to join the two pieces back into the original image and render the image into a pdf using the QPdfWriter. My problem is that I am struggling figuring out how to join the image pieces together.

    thanking you in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do I join two QImages to form one Image

    1) Create an image that is large enough to contain both parts
    2) Create a QPainter on that image
    3) Paint the two smaller images into the larger image.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Post Re: How do I join two QImages to form one Image

    Hello,
    below is an untested code snippet. I did something like this with QPixmap. As both QImage and QPixmap are paint devices, it should work with QImage too. Idea:
    Create an image of the desired result size and draw your two images using a painter into the result image. See the documentation of QPainter::drawImage() to find the method that best fits your needs.
    Qt Code:
    1. QImage image1 = ...; // your images
    2. QImage image2 = ...;
    3. QImage result(resultWidth, resultHeight, resultFormat); // image to hold the join of image 1 & 2
    4. QPainter painter(&result);
    5. painter.drawImage(x1, y1, image1); // xi, yi is the position for imagei
    6. painter.drawImage(x2, y2, image2);
    To copy to clipboard, switch view to plain text mode 

    Best regards
    ars

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

    Default Re: How do I join two QImages to form one Image

    Quote Originally Posted by ayanda83 View Post
    Small issue, I have an image which I split into two images using the QImage::copy() function. I then did some custom painting on each piece of the image and now I want to join the two pieces back into the original image and render the image into a pdf using the QPdfWriter. My problem is that I am struggling figuring out how to join the image pieces together.
    You can also not split the image in the first place. What is the point of splitting the images if you are going to be joining them again?
    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.


Similar Threads

  1. Image as window form
    By Ockonal in forum Qt Programming
    Replies: 5
    Last Post: 3rd April 2011, 09:16
  2. QGraphicsScene with 4 QImages
    By Morgan Cormier in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2011, 11:06
  3. Replies: 5
    Last Post: 22nd October 2010, 09:29
  4. setting an image on the form
    By Yayati.Ekbote in forum Newbie
    Replies: 6
    Last Post: 15th March 2010, 11:39
  5. Question about QImages
    By SkripT in forum Qt Programming
    Replies: 14
    Last Post: 27th January 2006, 11: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.