Display an Image Using PySide

Problem

You want to access a Draft.Image as a byte array and display it with PySide.

Solution

import Draft

# Required imports for using PySide
import sys
from PySide.QtCore import *
from PySide.QtGui import *

# Read an image from file and creates an ARGB32 string representing the image
img = Draft.Image.ReadFromFile( '//path/to/in.exr' )
imgAsByteArray = img.ToBytes()

# Displays the image using PySide
app = QApplication( sys.argv )
label = QLabel()

imgQT = QImage( imgAsByteArray, img.width, img.height, QImage.Format_ARGB32 )
pixMap = QPixmap.fromImage( imgQT )

label.setPixmap( pixMap )
label.show()

app.exec_()

Discussion

To display an image using PySide you first need to load the image in memory. Then, you can create a byte array representing the image using:

imgAsByteArray = img.ToBytes()

For more details on the syntax used by PySide, you can consult the PySide Documentation.