本文整理匯總了Python中PySide2.QtCore.QBuffer方法的典型用法代碼示例。如果您正苦於以下問題:Python QtCore.QBuffer方法的具體用法?Python QtCore.QBuffer怎麽用?Python QtCore.QBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PySide2.QtCore
的用法示例。
在下文中一共展示了QtCore.QBuffer方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: fromqimage
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.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()
b.write(buffer.data())
buffer.close()
b.seek(0)
return Image.open(b)
示例2: fromqimage
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.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: add_marker_from_svg
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QBuffer [as 別名]
def add_marker_from_svg(file_path, marker_name, pixel_x=10, pixel_y=None,
isLSBFirst=False, isUpToDown=False):
"""adds a new marker bitmap from a vector graphic (svg)"""
# get an icon from the svg rendered with the given pixel
from PySide2 import QtCore, QtGui
pixel_y = pixel_y or pixel_x
icon = QtGui.QIcon(file_path)
icon = QtGui.QBitmap(icon.pixmap(pixel_x, pixel_y))
# create a XMP-icon
buffer=QtCore.QBuffer()
buffer.open(buffer.WriteOnly)
icon.save(buffer,"XPM")
buffer.close()
# get a string from the XMP-icon
ary = str(buffer.buffer(), "utf8")
ary = ary.split("\n", 1)[1]
ary = ary.replace('\n', "").replace('"', "").replace(";", "")
ary = ary.replace("}", "").replace("#", "x").replace(".", " ")
string = str.join("", ary.split(",")[3:])
# add the new marker style
setattr(coin.SoMarkerSet, marker_name, coin.SoMarkerSet.getNumDefinedMarkers())
coin.SoMarkerSet.addMarker(getattr(coin.SoMarkerSet, marker_name),
coin.SbVec2s([pixel_x, pixel_y]), string,
isLSBFirst, isUpToDown)
示例4: fromqpixmap
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.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)