本文整理汇总了Python中PySide.QtCore.QBuffer方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QBuffer方法的具体用法?Python QtCore.QBuffer怎么用?Python QtCore.QBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtCore
的用法示例。
在下文中一共展示了QtCore.QBuffer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fromqimage
# 需要导入模块: from PySide import QtCore [as 别名]
# 或者: from PySide.QtCore import QBuffer [as 别名]
def fromqimage(im):
"""
:param im: A PIL Image object, or a file name
(given either as Python string or a PyQt string object)
"""
buffer = QBuffer()
buffer.open(QIODevice.ReadWrite)
# preserve alha channel with png
# otherwise ppm is more friendly with Image.open
if im.hasAlphaChannel():
im.save(buffer, 'png')
else:
im.save(buffer, 'ppm')
b = BytesIO()
try:
b.write(buffer.data())
except TypeError:
# workaround for Python 2
b.write(str(buffer.data()))
buffer.close()
b.seek(0)
return Image.open(b)
示例2: fromqimage
# 需要导入模块: from PySide import QtCore [as 别名]
# 或者: from PySide.QtCore import QBuffer [as 别名]
def fromqimage(im):
"""
:param im: A PIL Image object, or a file name
(given either as Python string or a PyQt string object)
"""
buffer = QBuffer()
buffer.open(QIODevice.ReadWrite)
# preserve alpha channel with png
# otherwise ppm is more friendly with Image.open
if im.hasAlphaChannel():
im.save(buffer, 'png')
else:
im.save(buffer, 'ppm')
b = BytesIO()
try:
b.write(buffer.data())
except TypeError:
# workaround for Python 2
b.write(str(buffer.data()))
buffer.close()
b.seek(0)
return Image.open(b)
示例3: getIcon
# 需要导入模块: from PySide import QtCore [as 别名]
# 或者: from PySide.QtCore import QBuffer [as 别名]
def getIcon(obj,disabled=False,path=None):
if not path:
path = iconPath
if not getattr(obj,'_icon',None):
obj._icon = addIconToFCAD(obj._iconName,path)
if not disabled:
return obj._icon
if not getattr(obj,'_iconDisabled',None):
name = getattr(obj,'_iconDisabledName',None)
if name:
obj._iconDisabled = addIconToFCAD(name,path)
else:
key = os.path.join(path,obj._iconName) + '.disabled'
fmt = None
try:
if FreeCADGui.isIconCached(key):
obj._iconDisabled = key
return key
else:
fmt = 'PNG'
except Exception:
pass
pixmap = FreeCADGui.getIcon(obj._icon).pixmap(*iconSize,mode=QIcon.Disabled)
icon = QIcon(pixmapDisabled)
icon.paint(QPainter(pixmap),0,0,iconSize[0],iconSize[1],Qt.AlignCenter)
data = QByteArray()
buf = QBuffer(data)
buf.open(QIODevice.WriteOnly)
if fmt:
pixmap.save(buf, fmt)
FreeCADGui.addIcon(key,data.data(),fmt)
else:
pixmap.save(buf, 'XPM')
key = data.data().decode('latin1')
obj._iconDisabled = key
return obj._iconDisabled
示例4: fromqpixmap
# 需要导入模块: from PySide import QtCore [as 别名]
# 或者: from PySide.QtCore import QBuffer [as 别名]
def fromqpixmap(im):
return fromqimage(im)
# buffer = QBuffer()
# buffer.open(QIODevice.ReadWrite)
# # im.save(buffer)
# # What if png doesn't support some image features like animation?
# im.save(buffer, 'ppm')
# bytes_io = BytesIO()
# bytes_io.write(buffer.data())
# buffer.close()
# bytes_io.seek(0)
# return Image.open(bytes_io)
示例5: _qimage_to_pil_image
# 需要导入模块: from PySide import QtCore [as 别名]
# 或者: from PySide.QtCore import QBuffer [as 别名]
def _qimage_to_pil_image(qimg):
buffer = QtCore.QBuffer()
buffer.open(QtCore.QIODevice.ReadWrite)
qimg.save(buffer, "PNG")
bytes_io = io.BytesIO()
bytes_io.write(buffer.data().data())
buffer.close()
bytes_io.seek(0)
return Image.open(bytes_io)