コード例 #1
0
    def toQImage(self, filepath):

        ibuf = ImageBuf(filepath)
        try:
            bufok = ibuf.read(subimage=0,
                              miplevel=0,
                              force=True,
                              convert=oiio.UINT8)
        except Exception as ex:
            print(ex)
            return None
        if not bufok:
            return None
        spec = ibuf.spec()

        width = spec.width
        height = spec.height

        # Expect the channel to be RGB from the beginning.
        # It might not work if it is a format like ARGB.
        # qimage = QtGui.QImage(width, height, QtGui.QImage.Format_RGB888)
        roi = oiio.ROI(0, width, 0, height, 0, 1, 0, 3)
        try:
            orgimg = Image.fromarray(ibuf.get_pixels(oiio.UINT8, roi))
            # for ImageQt source format error
            if orgimg.mode in self.mw.shot.NO_SUPPORT_IMAGEQT:
                orgimg = orgimg.convert('RGB')
            if self.mw.thumbnail_bright != self.mw.THUMB_DEFALUT_BRIGHT:
                eim = ImageEnhance.Brightness(orgimg)
                orgimg = eim.enhance(self.mw.thumbnail_bright)

            qimage = ImageQt(orgimg)
            # workaround https://bugreports.qt.io/browse/PYSIDE-884
            # output QImage to a file and reRead qimage
            wksavepath = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation)
            wksavepath = wksavepath + "/{0}/sequencegrab.jpg".format(
                self.mw.APPID)
            qimage.save(wksavepath, "jpg")
            wkqim = QImage(wksavepath)
            qimage = wkqim
            os.remove(wksavepath)

        except Exception as ex:
            print(ex)
            return None
        return (qimage)