当前位置: 首页>>代码示例>>Python>>正文


Python QImage.Format_RGB32方法代码示例

本文整理汇总了Python中PyQt5.QtGui.QImage.Format_RGB32方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.Format_RGB32方法的具体用法?Python QImage.Format_RGB32怎么用?Python QImage.Format_RGB32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtGui.QImage的用法示例。


在下文中一共展示了QImage.Format_RGB32方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: expandAndFormat

# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGB32 [as 别名]
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 
开发者ID:GDQuest,项目名称:krita-batch-exporter,代码行数:18,代码来源:Infrastructure.py

示例2: _toqclass_helper

# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGB32 [as 别名]
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} 
开发者ID:tp4a,项目名称:teleport,代码行数:42,代码来源:ImageQt.py

示例3: qimg2nparr

# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGB32 [as 别名]
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 
开发者ID:KUR-creative,项目名称:SickZil-Machine,代码行数:15,代码来源:imutils.py

示例4: setup2

# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGB32 [as 别名]
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)) 
开发者ID:lutusp,项目名称:PLSDR,代码行数:10,代码来源:Waterfall.py

示例5: createEditor

# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGB32 [as 别名]
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 
开发者ID:jopohl,项目名称:urh,代码行数:32,代码来源:ComboBoxDelegate.py

示例6: _toqclass_helper

# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGB32 [as 别名]
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
    } 
开发者ID:tp4a,项目名称:teleport,代码行数:47,代码来源:ImageQt.py

示例7: _toqclass_helper

# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGB32 [as 别名]
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
    } 
开发者ID:holzschu,项目名称:python3_ios,代码行数:47,代码来源:ImageQt.py

示例8: drawThreshMask

# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGB32 [as 别名]
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() 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:45,代码来源:TrackerViewerAux.py

示例9: _toqclass_helper

# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGB32 [as 别名]
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
    } 
开发者ID:skylander86,项目名称:lambda-text-extractor,代码行数:47,代码来源:ImageQt.py


注:本文中的PyQt5.QtGui.QImage.Format_RGB32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。