Q:

Python pymysql: How to load an image from database? 

I want to load and display an image from my database within a PyQt5 window. 
But my script doesn't work. 
    connection = None
    result = None

    try:
        connection = pymysql.connect(host = 'localhost',
                                     user = 'root',
                                     db = 'mydatabase',
                                     cursorclass = pymysql.cursors. DictCursor)
        try:
            with connection.cursor() as cursor:
                sql = "SELECT image FROM mydatabase"
                cursor.execute(sql)
                result = cursor.fetchall() #Get all values from the image column

                image = QImage()
                image.load(result[0]['Image']) #Load image from the first row

                label = QLabel()
                label.setPixmap(QPixmap.fromImage(image))
                self.grid.addWidget(label, 0, 0)
        finally:
            connection.close()

What should I do to display the image? 

A:

The load method only takes a file-path or an IODevice, whereas you seem to be passing in the raw image data as bytes. 
Try this, instead:
image = QImage.fromData(result[0]['Image'])

To save the image, do this:
image.save('image.png')

