Search code examples
pythonimageqtpyqtraster

Procedurally Create-Generate a Raster Image with PyQt


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.


Solution

  • 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')