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=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 _update(self): if self.value: # w, h = self.control.width(), self.control.height() # img = self.value.get_image_data(size=(w, h)) img = self.value.get_image_data() if img is not None: s = img.shape if s: im = QImage(img, s[1], s[0], QImage.Format_RGB32) # im = QImage(img, s[1], s[0], QImage.Format_RGB16) if self.swap: im = QImage.rgbSwapped(im) pix = QPixmap.fromImage(im) self.control.setPixmap(pix)
def set_frame(self): ok, data = self.cap.read() shape = data.shape im = QImage(data, shape[1], shape[0], QImage.Format_RGB888) pix = QPixmap.fromImage(QImage.rgbSwapped(im)) self.label.setPixmap(pix)