本文整理汇总了Python中PyQt4.Qt.QImage.fromData方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.fromData方法的具体用法?Python QImage.fromData怎么用?Python QImage.fromData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QImage
的用法示例。
在下文中一共展示了QImage.fromData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_image
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import fromData [as 别名]
def load_image(self, data):
self.is_valid = False
try:
fmt = identify_data(data)[-1].encode('ascii')
except Exception:
fmt = b''
self.original_image_format = fmt.decode('ascii').lower()
self.selection_state.reset()
self.original_image_data = data
self.current_image = i = self.original_image = (
QImage.fromData(data, format=fmt) if fmt else QImage.fromData(data))
self.is_valid = not i.isNull()
self.update()
self.image_changed.emit(self.current_image)
示例2: magick_to_qimage
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import fromData [as 别名]
def magick_to_qimage(img):
fmt = get_pixel_map()
# ImageMagick can output only output raw data in some formats that can be
# read into QImage directly, if the QImage format is not one of those, use
# PNG
if fmt in {'RGBA', 'BGRA'}:
w, h = img.size
img.depth = 8 # QImage expects 8bpp
raw = img.export(fmt)
i = QImage(raw, w, h, QImage.Format_ARGB32)
del raw # According to the documentation, raw is supposed to not be deleted, but it works, so make it explicit
return i
else:
raw = img.export('PNG')
return QImage.fromData(QByteArray(raw), 'PNG')
示例3: get_service_icon
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import fromData [as 别名]
def get_service_icon(self, id, name, url):
icon, st = None, self.app.preferences.settings
if not st.contains('icon/'+name):
icon = get_favicon(url)
if icon:
icon = QIcon(QPixmap.fromImage(QImage.fromData(icon)))
print name, "icon loaded?", not icon.isNull()
if not icon.isNull():
st.setValue('icon/'+name, icon)
else: print "error while loading", name, "icon"
else:
icon = st.value('icon/'+name, None)
if icon: icon = QIcon(icon)
if icon:
self.app.preferences.ui.accountsTabWidget.setTabIcon(id, icon)
return icon
示例4: get_service_icon
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import fromData [as 别名]
def get_service_icon(self, name, url):
key = "service/" + name
if key in self.icons:
return self.icons[key]
icon, st = None, self.app.accounts.settings
if not st.contains('icon/'+name):
icon = get_favicon(url)
if icon:
icon = QIcon(QPixmap.fromImage(QImage.fromData(icon)))
#print name, "icon loaded?", not icon.isNull()
if not icon.isNull():
st.setValue('icon/'+name, icon)
else: print "[ERROR] while loading", name, "icon"
else:
icon = st.value('icon/'+name, None)
if icon: icon = QIcon(icon)
if icon:
self.icons[key] = icon
return icon