Python PyQt5.QtGui.QImage.Format_RGB32() Examples
The following are 12
code examples of PyQt5.QtGui.QImage.Format_RGB32().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PyQt5.QtGui.QImage
, or try the search function
.
Example #1
Source File: Infrastructure.py From krita-batch-exporter with GNU General Public License v3.0 | 6 votes |
def expandAndFormat(img, margin=0, is_jpg=False): """ Draws the image with transparent background if `is_jpg == False`, otherwise with a white background. It's done in a single function, to avoid creating extra images """ if not margin and not is_jpg: return img corner = QSize(margin, margin) white = QColor(255, 255, 255) if is_jpg else QColor(255, 255, 255, 0) canvas = QImage( img.size() + corner * 2, QImage.Format_RGB32 if is_jpg else QImage.Format_ARGB32 ) canvas.fill(white) p = QPainter(canvas) p.drawImage(margin, margin, img) return canvas
Example #2
Source File: ComboBoxDelegate.py From urh with GNU General Public License v3.0 | 6 votes |
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex): editor = QComboBox(parent) if sys.platform == "win32": # Ensure text entries are visible with windows combo boxes editor.setMinimumHeight(self.sizeHint(option, index).height() + 10) editor.addItems(self.items) if self.is_editable: editor.setEditable(True) editor.setInsertPolicy(QComboBox.NoInsert) if self.current_edit_text: editor.setEditText(self.current_edit_text) if self.colors: img = QImage(16, 16, QImage.Format_RGB32) painter = QPainter(img) painter.fillRect(img.rect(), Qt.black) rect = img.rect().adjusted(1, 1, -1, -1) for i, item in enumerate(self.items): color = self.colors[i] painter.fillRect(rect, QColor(color.red(), color.green(), color.blue(), 255)) editor.setItemData(i, QPixmap.fromImage(img), Qt.DecorationRole) del painter editor.currentIndexChanged.connect(self.currentIndexChanged) editor.editTextChanged.connect(self.on_edit_text_changed) return editor
Example #3
Source File: ImageQt.py From teleport with Apache License 2.0 | 5 votes |
def _toqclass_helper(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 = str(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) __data = data or align8to32(im.tobytes(), im.size[0], im.mode) return {"data": __data, "im": im, "format": format, "colortable": colortable}
Example #4
Source File: ImageQt.py From teleport with Apache License 2.0 | 5 votes |
def _toqclass_helper(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 = str(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) __data = data or align8to32(im.tobytes(), im.size[0], im.mode) return {"data": __data, "im": im, "format": format, "colortable": colortable}
Example #5
Source File: imutils.py From SickZil-Machine with GNU Affero General Public License v3.0 | 5 votes |
def qimg2nparr(qimg): ''' convert rgb qimg -> cv2 bgr image ''' #NOTE: it would be changed or extended to input image shape # Now it just used for canvas stroke.. but in the future... I don't know :( #qimg = qimg.convertToFormat(QImage.Format_RGB32) #qimg = qimg.convertToFormat(QImage.Format_RGB888) h,w = qimg.height(), qimg.width() ptr = qimg.constBits() ptr.setsize(h * w * 4) print(h,w,ptr) return np.frombuffer(ptr, np.uint8).reshape(h, w, 4) # Copies the data #return np.array(ptr).reshape(h, w, 3) # Copies the data
Example #6
Source File: Waterfall.py From PLSDR with GNU General Public License v3.0 | 5 votes |
def setup2(self): dw = self.dw dh = self.dh self.acquire_essential() if dw != self.dw or dh != self.dh: self.image = QImage(self.dw,self.dh,QImage.Format_RGB32) p = QPainter(self.image) p.fillRect(0, 0, self.width(), self.height(),QtGui.QColor(0,0,0))
Example #7
Source File: ImageQt.py From FODI with GNU General Public License v3.0 | 5 votes |
def _toqclass_helper(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 = str(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) __data = data or align8to32(im.tobytes(), im.size[0], im.mode) return {"data": __data, "im": im, "format": format, "colortable": colortable}
Example #8
Source File: ImageQt.py From teleport with Apache License 2.0 | 4 votes |
def _toqclass_helper(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? if py3: im = str(im.toUtf8(), "utf-8") else: 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) __data = data or align8to32(im.tobytes(), im.size[0], im.mode) return { 'data': __data, 'im': im, 'format': format, 'colortable': colortable }
Example #9
Source File: ImageQt.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 4 votes |
def _toqclass_helper(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? if py3: im = str(im.toUtf8(), "utf-8") else: im = unicode(im.toUtf8(), "utf-8") # noqa: F821 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) __data = data or align8to32(im.tobytes(), im.size[0], im.mode) return { 'data': __data, 'im': im, 'format': format, 'colortable': colortable }
Example #10
Source File: TrackerViewerAux.py From tierpsy-tracker with MIT License | 4 votes |
def drawThreshMask(self, worm_img, worm_qimg, row_data, read_center=True): #in very old versions of the tracker I didn't save the area in trajectories table, #let's assign a default value to deal with this cases if 'area' in row_data: min_blob_area = row_data['area'] / 2 else: min_blob_area = 10 c1, c2 = (row_data['coord_x'], row_data[ 'coord_y']) if read_center else (-1, -1) worm_mask, worm_cnt, _ = getWormMask(worm_img, row_data['threshold'], strel_size=self.strel_size, roi_center_x=c1, roi_center_y=c2, min_blob_area=min_blob_area, is_light_background = self.is_light_background) worm_mask = QImage( worm_mask.data, worm_mask.shape[1], worm_mask.shape[0], worm_mask.strides[0], QImage.Format_Indexed8) worm_mask = worm_mask.convertToFormat( QImage.Format_RGB32, Qt.AutoColor) worm_mask = QPixmap.fromImage(worm_mask) worm_mask = worm_mask.createMaskFromColor(Qt.black) p = QPainter(worm_qimg) p.setPen(QColor(0, 204, 102)) p.drawPixmap(worm_qimg.rect(), worm_mask, worm_mask.rect()) if False: #test skeletonization skeleton, ske_len, cnt_side1, cnt_side2, cnt_widths, cnt_area = \ getSkeleton(worm_cnt, np.zeros(0), 49) for cnt in skeleton, cnt_side1, cnt_side2: p.setPen(Qt.black) polyline = QPolygonF() for point in cnt: polyline.append(QPointF(*point)) p.drawPolyline(polyline) p.end()
Example #11
Source File: ImageQt.py From lambda-text-extractor with Apache License 2.0 | 4 votes |
def _toqclass_helper(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? if str is bytes: im = unicode(im.toUtf8(), "utf-8") else: im = str(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) __data = data or align8to32(im.tobytes(), im.size[0], im.mode) return { 'data': __data, 'im': im, 'format': format, 'colortable': colortable }
Example #12
Source File: ImageQt.py From lambda-text-extractor with Apache License 2.0 | 4 votes |
def _toqclass_helper(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? if str is bytes: im = unicode(im.toUtf8(), "utf-8") else: im = str(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) __data = data or align8to32(im.tobytes(), im.size[0], im.mode) return { 'data': __data, 'im': im, 'format': format, 'colortable': colortable }