我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用PyQt4.QtGui.qRgb()。
def _create_icon(self, color_map_name, image, values): """" :type color_map_name: str :type image: QImage :type values: np.ndarray """ color_map = ScalarMappable(cmap=color_map_name) rgba = color_map.to_rgba(values, bytes=True) color_table = [qRgb(c[0], c[1], c[2]) for c in rgba] image.setColorTable(color_table) return QPixmap.fromImage(image).scaledToWidth(128)
def rgb(r, g, b): # use qRgb to pack the colors, and then turn the resulting long # into a negative integer with the same bitpattern. return (qRgb(r, g, b) & 0xffffff) - 0x1000000 ## # An PIL image wrapper for Qt. This is a subclass of PyQt4's QImage # class. # # @param im A PIL Image object, or a file name (given either as Python # string or a PyQt string object).
def loadDisparities(self): if not self.enableDisparity: return if not self.showDisparity: return filename = self.getDisparityFilename() if not filename: self.dispImg = None return # If we have everything and the filename did not change, then we are good if self.dispImg and filename == self.currentDispFile: return # Clear the current labels first self.dispImg = None try: self.dispImg = Image.open(filename) except IOError as e: # This is the error if the file does not exist message = "Error parsing disparities in {0}. Message: {1}".format( filename, e.strerror ) self.statusBar().showMessage(message) self.dispImg = None if self.dispImg: dispNp = np.array( self.dispImg ) dispNp /= 128 dispNp.round() dispNp = np.array( dispNp , dtype=np.uint8 ) dispQt = QtGui.QImage( dispNp.data , dispNp.shape[1] , dispNp.shape[0] , QtGui.QImage.Format_Indexed8 ) colortable = [] for i in range(256): color = self.colormap.to_rgba(i) colorRgb = ( int(color[0]*255) , int(color[1]*255) , int(color[2]*255) ) colortable.append( QtGui.qRgb( *colorRgb ) ) dispQt.setColorTable( colortable ) dispQt = dispQt.convertToFormat( QtGui.QImage.Format_ARGB32_Premultiplied ) self.dispOverlay = dispQt # Remember the filename loaded self.currentDispFile = filename # Remember the status bar message to restore it later restoreMessage = self.statusBar().currentMessage() # Restore the message self.statusBar().showMessage( restoreMessage ) ############################# ## Drawing ############################# # This method is called when redrawing everything # Can be manually triggered by self.update() # Note that there must not be any other self.update within this method # or any methods that are called within