def fromqimage(im):
 buffer = QBuffer()
 buffer.open(QIODevice.ReadWrite)
 if im.hasAlphaChannel():
  im.save(buffer, 'png')
 else:
  im.save(buffer, 'ppm')
 b = BytesIO()
 try:
  b.write(buffer.data())
 except TypeError:
  b.write(str(buffer.data()))
 buffer.close()
 b.seek(0)
 return Image.open(b)

def fromqimage ( im ) : buffer = QBuffer ( ) buffer . open ( QIODevice . ReadWrite ) if im . hasAlphaChannel ( ) : im . save ( buffer , 'png' ) else : im . save ( buffer , 'ppm' ) b = BytesIO ( ) try : b . write ( buffer . data ( ) ) except TypeError : b . write ( str ( buffer . data ( ) ) ) buffer . close ( ) b . seek ( 0 ) return Image . open ( b )
creates an image instance from a qimage image .