當前位置: 首頁>>代碼示例>>Python>>正文


Python QImage.Format_Indexed8方法代碼示例

本文整理匯總了Python中PyQt4.QtGui.QImage.Format_Indexed8方法的典型用法代碼示例。如果您正苦於以下問題:Python QImage.Format_Indexed8方法的具體用法?Python QImage.Format_Indexed8怎麽用?Python QImage.Format_Indexed8使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt4.QtGui.QImage的用法示例。


在下文中一共展示了QImage.Format_Indexed8方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.QtGui.QImage import Format_Indexed8 [as 別名]
def __init__(self, color_maps=None, parent=None):
        QComboBox.__init__(self, parent)
        self.setMaxVisibleItems(10)
        self.setStyleSheet("QComboBox { combobox-popup: 0; }")

        if color_maps is None:
            color_maps = self._type_sorted_color_maps()

        self.setMinimumWidth(170)
        self.setMaximumWidth(170)
        self.setMinimumHeight(30)

        self.setIconSize(QSize(128, 16))

        icon_width = 256
        icon_height = 16
        values = np.linspace(0, 1, icon_width)
        color_indexes = np.linspace(0, 255, icon_width, dtype=np.uint8)
        color_indexes = np.tile(color_indexes, icon_height)
        image = QImage(color_indexes.data, icon_width, icon_height, QImage.Format_Indexed8)

        for index, item in enumerate(color_maps):
            self.addItem(item)
            pix_map = self._create_icon(item, image, values)
            self.setItemData(index, "", Qt.DisplayRole)
            self.setItemData(index, item, Qt.ToolTipRole)
            self.setItemData(index, pix_map, Qt.DecorationRole) 
開發者ID:equinor,項目名稱:segyviewer,代碼行數:29,代碼來源:colormapcombo.py

示例2: _toqclass_helper

# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.QtGui.QImage import Format_Indexed8 [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

示例3: _toqclass_helper

# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.QtGui.QImage import Format_Indexed8 [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

示例4: __init__

# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.QtGui.QImage import Format_Indexed8 [as 別名]
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 Image.isStringType(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.tostring("raw", "BGRX")
            format = QImage.Format_RGB32
        elif im.mode == "RGBA":
            try:
                data = im.tostring("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.tostring()

        QImage.__init__(self, self.__data, im.size[0], im.size[1], format)

        if colortable:
            self.setColorTable(colortable) 
開發者ID:awslabs,項目名稱:mxnet-lambda,代碼行數:48,代碼來源:ImageQt.py

示例5: _toqclass_helper

# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.QtGui.QImage import Format_Indexed8 [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


注:本文中的PyQt4.QtGui.QImage.Format_Indexed8方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。