Domanda

What would be a short simple way to generate a raster image with PyQt? Ideally I would like to supply a function with a desired image resolution (such as 16x16 pixels) and save the resulted image to drive as a simple JPG.

È stato utile?

Soluzione

Use the QImage class:

def create_image(width, height, path):
    img = QtGui.QImage(width, height, QtGui.QImage.Format_RGB32)
    img.fill(QtCore.Qt.red)
    img.save(path, 'JPG')
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top