An example of pyqt5 scaling the picture


As follows:

def shrinkImage(self):
	Zooms in
	Scale = 0.8 × 20% reduction each time
	IMG = qimage (self. Path) × create picture instance
	mgnWidth = int(originWidth * scale)  
	Mgnheight = int (originheight * scale)
	size = QSize(mgnWidth, mgnHeight)
	Piximg = qpixmap. Fromimage (img. Scaled (size, QT. Ignoreaspectratio)) (modify the image instance size and generate the qpixmap instance from the qimage instance for placement in the qlabel control
    self.imageLabel.resize(mgnWidth, mgnHeight)

The basic idea is to build a qimage instance, then scale the instance and import it into qpixmap. The original scaled function in qpixmap can’t realize the scaling function directly. It’s not clear why for now. If you see this article and know why, thank you!

The above example of pyqt5‘s image zooming is all the content shared by Xiaobian. I hope it can give you a reference, and I hope you can support developepaer more.