سؤال

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.

هل كانت مفيدة؟

المحلول

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')
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top