Combine several images into one?
-
I've been using PyQt5 for just a few days but I'm doing pretty well except for one thing I just can't figure out.
I have three images (parts of a whole) that I want to combine into one. I tried various things but messed up every time. The most promising looks like QPainter but I can't seem to figure out the arguments and I can't find any simple examples online anywhere.
Anyway, I have three images but to start I'm trying with just one like this:
for part in self.parts: _width += part.width() _img = QPixmap(_width,self.SrcImg.height())So the target image is full size of the three combined. To start I'm only trying to get one image painted onto it but that's failing miserably no matter what I try. Here's what I thought it should look like after reading the docs
painter = QPainter(_img) painter.setCompositionMode(QPainter.CompositionMode_SourceAtop) painter.drawImage(0,0,self.parts[0])But that gives an error:
painter.drawImage(0,0,self.parts[0])
TypeError: arguments did not match any overloaded call:
drawImage(self, QRectF, QImage): argument 1 has unexpected type 'int'
drawImage(self, QRect, QImage): argument 1 has unexpected type 'int'So I tried making a QRect(0,0,self.parts[0].width,self.parts[0].height()) but then the error just changes from type int to type QRect
It looks really simple but I'm just not getting it for some reason
-
I've been using PyQt5 for just a few days but I'm doing pretty well except for one thing I just can't figure out.
I have three images (parts of a whole) that I want to combine into one. I tried various things but messed up every time. The most promising looks like QPainter but I can't seem to figure out the arguments and I can't find any simple examples online anywhere.
Anyway, I have three images but to start I'm trying with just one like this:
for part in self.parts: _width += part.width() _img = QPixmap(_width,self.SrcImg.height())So the target image is full size of the three combined. To start I'm only trying to get one image painted onto it but that's failing miserably no matter what I try. Here's what I thought it should look like after reading the docs
painter = QPainter(_img) painter.setCompositionMode(QPainter.CompositionMode_SourceAtop) painter.drawImage(0,0,self.parts[0])But that gives an error:
painter.drawImage(0,0,self.parts[0])
TypeError: arguments did not match any overloaded call:
drawImage(self, QRectF, QImage): argument 1 has unexpected type 'int'
drawImage(self, QRect, QImage): argument 1 has unexpected type 'int'So I tried making a QRect(0,0,self.parts[0].width,self.parts[0].height()) but then the error just changes from type int to type QRect
It looks really simple but I'm just not getting it for some reason
@pmeloy said in Combine several images into one?:
QRect(0,0,self.parts[0].width,self.parts[0].height())
Please take a closer look at that line: it is quite apparent what is wrong here (hint: self.parts[0].width).