本文整理汇总了Python中PyQt5.QtCore.QBuffer方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QBuffer方法的具体用法?Python QtCore.QBuffer怎么用?Python QtCore.QBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore
的用法示例。
在下文中一共展示了QtCore.QBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resize_image
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QBuffer [as 别名]
def resize_image(cover_image_raw):
if isinstance(cover_image_raw, QtGui.QImage):
cover_image = cover_image_raw
else:
cover_image = QtGui.QImage()
cover_image.loadFromData(cover_image_raw)
# Resize image to what literally everyone
# agrees is an acceptable cover size
cover_image = cover_image.scaled(
420, 600, QtCore.Qt.IgnoreAspectRatio)
byte_array = QtCore.QByteArray()
buffer = QtCore.QBuffer(byte_array)
buffer.open(QtCore.QIODevice.WriteOnly)
cover_image.save(buffer, 'jpg', 75)
cover_image_final = io.BytesIO(byte_array)
cover_image_final.seek(0)
return cover_image_final.getvalue()
示例2: fromqimage
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.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)
示例3: fromqimage
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.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)
示例4: fromqimage
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.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)
示例5: capture_widget
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QBuffer [as 别名]
def capture_widget(widget, path=None):
"""Grab an image of a Qt widget
Args:
widget: The Qt Widget to capture
path (optional): The path to save to. If not provided - will return image data.
Returns:
If a path is provided, the image will be saved to it.
If not, the PNG buffer will be returned.
"""
pixmap = widget.grab()
if path:
pixmap.save(path)
else:
image_buffer = QtCore.QBuffer()
image_buffer.open(QtCore.QIODevice.ReadWrite)
pixmap.save(image_buffer, "PNG")
return image_buffer.data().data()
示例6: UpdateListItem
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QBuffer [as 别名]
def UpdateListItem(self, updateTooltipPreview=False):
"""
Updates the list item
"""
if not hasattr(self, 'listitem'): return
if self.listitem is None: return
if updateTooltipPreview:
# It's just like Qt to make this overly complicated. XP
img = self.renderInLevelIcon()
byteArray = QtCore.QByteArray()
buf = QtCore.QBuffer(byteArray)
img.save(buf, 'PNG')
byteObj = bytes(byteArray)
b64 = base64.b64encode(byteObj).decode('utf-8')
self.listitem.setToolTip('<img src="data:image/png;base64,' + b64 + '" />')
self.listitem.setText(self.ListString())
示例7: createRequest
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QBuffer [as 别名]
def createRequest(self, op, originalReq, outgoingData):
"""创建请求
:param op: 操作类型见http://doc.qt.io/qt-5/qnetworkaccessmanager.html#Operation-enum
:param originalReq: 原始请求
:param outgoingData: 输出数据
"""
url = originalReq.url().toString()
if url.find('pos.baidu.com') > -1 and url.find('ltu=') > -1:
# 拦截百度联盟的广告
print('block:', url)
originalReq.setUrl(QUrl())
if op == self.PostOperation and outgoingData:
# 拦截或者修改post数据
# 读取后要重新设置,不然网站接收不到请求
data = outgoingData.readAll().data()
print('post data:', data)
# 修改data后重新设置
outgoingData = QBuffer(self)
outgoingData.setData(data)
return super(RequestInterceptor, self).createRequest(op, originalReq, outgoingData)
示例8: test_on_focus_changed_issue1484
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QBuffer [as 别名]
def test_on_focus_changed_issue1484(monkeypatch, qapp, caplog):
"""Check what happens when on_focus_changed is called with wrong args.
For some reason, Qt sometimes calls on_focus_changed() with a QBuffer as
argument. Let's make sure we handle that gracefully.
"""
monkeypatch.setattr(app, 'q_app', qapp)
buf = QBuffer()
app.on_focus_changed(buf, buf)
expected = "on_focus_changed called with non-QWidget {!r}".format(buf)
assert caplog.messages == [expected]
示例9: fromqpixmap
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.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)
示例10: get_zip_graphic
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QBuffer [as 别名]
def get_zip_graphic(self, name):
if os.path.exists("ecu.zip"):
zf = zipfile.ZipFile("ecu.zip", "r")
zname = "graphics/" + name + ".gif"
if not zname in zf.namelist():
zname = "graphics/" + name + ".GIF"
if zname in zf.namelist():
ba = core.QByteArray(zf.read(zname))
self.buffer = core.QBuffer()
self.buffer.setData(ba)
self.buffer.open(core.QIODevice.ReadOnly)
self.img = gui.QMovie(self.buffer, 'GIF')
示例11: pasted
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QBuffer [as 别名]
def pasted(self, checked):
clipboard = QApplication.clipboard()
mime = clipboard.mimeData()
if mime.hasImage():
pixmap = clipboard.pixmap()
byteArray = QByteArray()
buffer = QBuffer(byteArray)
pixmap.save(buffer, "PNG")
self.call("setClipboard", str(byteArray.toBase64(), sys.stdout.encoding))
示例12: procesarImagenCapturada
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QBuffer [as 别名]
def procesarImagenCapturada(self, requestId, imagen):
foto = QPixmap.fromImage(imagen)
buffer = QBuffer(self.byteArrayFoto)
buffer.open(QIODevice.WriteOnly)
buffer.close()
foto.save(buffer, "PNG")
fotoEscalada = foto.scaled(self.labelFoto.size())
self.labelFoto.setPixmap(fotoEscalada)
self.mostrarImagenCapturada()
示例13: get_prediction
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QBuffer [as 别名]
def get_prediction(self):
# See: https://stackoverflow.com/questions/1733096/convert-pyqt-to-pil-image.
buffer = QtCore.QBuffer()
buffer.open(QtCore.QIODevice.ReadWrite)
qimage = self.grabFramebuffer()
qimage.save(buffer, "PNG")
strio = io.BytesIO()
strio.write(buffer.data())
buffer.close()
strio.seek(0)
pil_im = Image.open(strio)
pil_im = pil_im.resize(self.scene.WINDOW_SIZE)
self.model.predict(pil_im)
示例14: capture_screenshot
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QBuffer [as 别名]
def capture_screenshot(self):
buffer = QtCore.QBuffer()
buffer.open(QtCore.QIODevice.ReadWrite)
qimage = self.grabFramebuffer()
result = qimage.save("screenshot_{0}.png".format(str(self.screenshot)).zfill(2))
self.screenshot += 1
示例15: cadProduto
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QBuffer [as 别名]
def cadProduto(self):
INSERI = CrudProduto()
INSERI.id = self.tx_idProduto.text()
INSERI.produto = self.tx_DescricaoProduto.text().upper()
if self.lb_FotoProduto.pixmap():
imagem = QPixmap(self.lb_FotoProduto.pixmap())
data = QByteArray()
buf = QBuffer(data)
imagem.save(buf, 'PNG')
INSERI.imagem = str(data.toBase64()).encode('utf8')[2:-1]
else:
INSERI.imagem = False
INSERI.categoria = self.cb_CategoriaProduto.currentData()
INSERI.marca = self.cb_MarcaProduto.currentData()
INSERI.estoqueMinimo = self.tx_EstoqueMinimoProduto.text()
INSERI.estoqueMaximo = self.tx_EstoqueMaximoProduto.text()
INSERI.obsProduto = self.tx_ObsProduto.text()
INSERI.valorCompra = self.tx_ValorCompraProduto.text().replace(",", ".")
INSERI.valorUnitario = self.tx_ValorUnitarioProduto.text().replace(",", ".")
INSERI.valorAtacado = self.tx_ValorAtacadoProduto.text().replace(",", ".")
INSERI.qtdeAtacado = self.tx_MinimoAtacado.text()
INSERI.inseriProduto()
self.janelaProdutos()
# Selecionando Produto