PDA

View Full Version : How do I join two QImages to form one Image



ayanda83
21st April 2015, 19:57
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.

anda_skoa
21st April 2015, 20:15
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,
_

ars
21st April 2015, 20:18
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.


QImage image1 = ...; // your images
QImage image2 = ...;
QImage result(resultWidth, resultHeight, resultFormat); // image to hold the join of image 1 & 2
QPainter painter(&result);
painter.drawImage(x1, y1, image1); // xi, yi is the position for imagei
painter.drawImage(x2, y2, image2);


Best regards
ars

wysota
21st April 2015, 22:10
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?