def convert_bitmap(image, width=0, height=0): if isinstance(image, ImageResource): pix = traitsui_convert_bitmap(image) elif isinstance(image, (PILImage.Image, )): try: data = image.tostring('raw', 'RGBA') except NotImplementedError: data = image.tobytes('raw', 'RGBA') im = QImage(data, image.size[0], image.size[1], QImage.Format_ARGB32) pix = QPixmap.fromImage(QImage.rgbSwapped(im)) else: s = image.shape if len(s) >= 2: pix = QPixmap.fromImage(array2qimage(image)) else: pix = QPixmap() if pix: if width > 0 and height > 0: pix = pix.scaled(width, height) elif width > 0: pix = pix.scaledToWidth(width) if height > 0: pix = pix.scaledToHeight(height) return pix
def convert_bitmap(image, width=None, height=None): pix = None if isinstance(image, ImageResource): pix = traitsui_convert_bitmap(image) elif isinstance(image, Image): # image = image.convert('RGBA') data = image.tostring('raw', 'RGBA') im = QImage(data, image.size[0], image.size[1], QImage.Format_ARGB32) pix = QPixmap.fromImage(QImage.rgbSwapped(im)) else: s = image.shape if len(s) >= 2: # im = QImage(image.tostring(),s[1], s[0], QImage.Format_RGB888) im = QImage(image, s[1], s[0], QImage.Format_RGB888) pix = QPixmap.fromImage(QImage.rgbSwapped(im)) else: pix = QPixmap() if pix: if width > 0 and height > 0: pix = pix.scaled(width, height) elif width > 0: pix = pix.scaledToWidth(width) if height > 0: pix = pix.scaledToHeight(height) return pix
def convert_bitmap(image, width=0, height=0): if isinstance(image, ImageResource): pix = traitsui_convert_bitmap(image) elif isinstance(image, (PILImage.Image,)): try: data = image.tostring('raw', 'RGBA') except NotImplementedError: data = image.tobytes('raw', 'RGBA') im = QImage(data, image.size[0], image.size[1], QImage.Format_ARGB32) pix = QPixmap.fromImage(QImage.rgbSwapped(im)) else: s = image.shape if len(s) >= 2: pix = QPixmap.fromImage(array2qimage(image)) else: pix = QPixmap() if pix: if width > 0 and height > 0: pix = pix.scaled(width, height) elif width > 0: pix = pix.scaledToWidth(width) if height > 0: pix = pix.scaledToHeight(height) return pix
def convert_bitmap(image, width=None, height=None): pix = None if isinstance(image, ImageResource): pix = traitsui_convert_bitmap(image) else: s = image.shape if len(s) >= 2: im = QImage(image.tostring(), s[1], s[0], QImage.Format_RGB888 # QImage.Format_RGB16 ) pix = QPixmap.fromImage(QImage.rgbSwapped(im)) if pix: if width > 0 and height > 0: pix = pix.scaled(width, height) elif width > 0: pix = pix.scaledToWidth(width) if height > 0: pix = pix.scaledToHeight(height) return pix
def convert_bitmap(image, width=None, height=None): pix = None if isinstance(image, ImageResource): pix = traitsui_convert_bitmap(image) else: s = image.shape if len(s) >= 2: im = QImage(image.tostring(), s[1], s[0], QImage.Format_RGB888 # QImage.Format_RGB16 ) pix = QPixmap.fromImage(QImage.rgbSwapped(im)) if pix: if width > 0 and height > 0: pix = pix.scaled(width, height) elif width > 0: pix = pix.scaledToWidth(width) if height > 0: pix = pix.scaledToHeight(height) return pix