def __init__(self, im): im_data = _toqclass_helper(im) QImage.__init__(self, im_data['data'], im_data['im'].size[0], im_data['im'].size[1], im_data['format']) if im_data['colortable']: self.setColorTable(im_data['colortable'])
def __init__(self, im): """ An PIL image wrapper for Qt. This is a subclass of PyQt's QImage class. :param im: A PIL Image object, or a file name (given either as Python string or a PyQt string object). """ im_data = _toqclass_helper(im) QImage.__init__(self, im_data['data'], im_data['im'].size[0], im_data['im'].size[1], im_data['format']) if im_data['colortable']: self.setColorTable(im_data['colortable'])
def __init__(self, im): data = None colortable = None stride = None # handle filename, if given instead of image name if hasattr(im, "toUtf8"): # FIXME - is this really the best way to do this? im = unicode(im.toUtf8(), "utf-8") if isPath(im): im = Image.open(im) if im.mode == "1": format = QImage.Format_Mono elif im.mode == "L": format = QImage.Format_Indexed8 colortable = [] for i in range(256): colortable.append(rgb(i, i, i)) stride = im.size[0] elif im.mode == "P": format = QImage.Format_Indexed8 colortable = [] palette = im.getpalette() for i in range(0, len(palette), 3): colortable.append(rgb(*palette[i:i+3])) stride = im.size[0] elif im.mode == "RGB": data = im.tobytes("raw", "BGRX") format = QImage.Format_RGB32 elif im.mode == "RGBA": try: data = im.tobytes("raw", "BGRA") except SystemError: # workaround for earlier versions r, g, b, a = im.split() im = Image.merge("RGBA", (b, g, r, a)) format = QImage.Format_ARGB32 else: raise ValueError("unsupported image mode %r" % im.mode) # must keep a reference, or Qt will crash! self.__data = data or im.tobytes() if stride is not None: QImage.__init__(self, self.__data, im.size[0], im.size[1], stride, format) else: QImage.__init__(self, self.__data, im.size[0], im.size[1], format) if colortable: self.setColorTable(colortable)
def __init__(self, im): """ A PIL image wrapper for Qt. @param im: A PIL Image object, or a file name (given either as Python string or a PyQt string object). """ im_data = _toqclass_helper(im) # must keep a reference, or Qt will crash! # Fixes https://github.com/python-pillow/Pillow/issues/1370 self.__data = im_data['data'] QImage.__init__(self, self.__data, im_data['im'].size[0], im_data['im'].size[1], im_data['format']) if im_data['colortable']: self.setColorTable(im_data['colortable'])
def __init__(self, im): data = None colortable = None # handle filename, if given instead of image name if hasattr(im, "toUtf8"): # FIXME - is this really the best way to do this? im = unicode(im.toUtf8(), "utf-8") if isPath(im): im = Image.open(im) if im.mode == "1": format = QImage.Format_Mono elif im.mode == "L": format = QImage.Format_Indexed8 colortable = [] for i in range(256): colortable.append(rgb(i, i, i)) elif im.mode == "P": format = QImage.Format_Indexed8 colortable = [] palette = im.getpalette() for i in range(0, len(palette), 3): colortable.append(rgb(*palette[i:i+3])) elif im.mode == "RGB": data = im.tobytes("raw", "BGRX") format = QImage.Format_RGB32 elif im.mode == "RGBA": try: data = im.tobytes("raw", "BGRA") except SystemError: # workaround for earlier versions r, g, b, a = im.split() im = Image.merge("RGBA", (b, g, r, a)) format = QImage.Format_ARGB32 else: raise ValueError("unsupported image mode %r" % im.mode) # must keep a reference, or Qt will crash! self.__data = data or im.tobytes() QImage.__init__(self, self.__data, im.size[0], im.size[1], format) if colortable: self.setColorTable(colortable)
def __init__(self, im): """ An PIL image wrapper for Qt. This is a subclass of PyQt's QImage class. :param im: A PIL Image object, or a file name (given either as Python string or a PyQt string object). """ im_data = _toqclass_helper(im) # must keep a reference, or Qt will crash! # All QImage constructors that take data operate on an existing # buffer, so this buffer has to hang on for the life of the image. # Fixes https://github.com/python-pillow/Pillow/issues/1370 self.__data = im_data['data'] QImage.__init__(self, self.__data, im_data['im'].size[0], im_data['im'].size[1], im_data['format']) if im_data['colortable']: self.setColorTable(im_data['colortable'])
def __init__(self, label, width, height): QImage.__init__(self, width, height, QImage.Format_RGB32) self.label = label self._update()