當前位置: 首頁>>代碼示例>>Python>>正文


Python QtCore.QBuffer方法代碼示例

本文整理匯總了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() 
開發者ID:BasioMeusPuga,項目名稱:Lector,代碼行數:22,代碼來源:sorter.py

示例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) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:26,代碼來源:ImageQt.py

示例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) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:22,代碼來源:ImageQt.py

示例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) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:26,代碼來源:ImageQt.py

示例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() 
開發者ID:tmr232,項目名稱:Sark,代碼行數:25,代碼來源:qt.py

示例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()) 
開發者ID:aboood40091,項目名稱:Miyamoto,代碼行數:21,代碼來源:items.py

示例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) 
開發者ID:PyQt5,項目名稱:PyQt,代碼行數:23,代碼來源:BlockRequest.py

示例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] 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:15,代碼來源:test_app.py

示例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) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:14,代碼來源:ImageQt.py

示例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') 
開發者ID:cedricp,項目名稱:ddt4all,代碼行數:14,代碼來源:displaymod.py

示例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)) 
開發者ID:raelgc,項目名稱:scudcloud,代碼行數:11,代碼來源:wrapper.py

示例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() 
開發者ID:andresnino,項目名稱:PyQt5,代碼行數:14,代碼來源:tomarFoto.py

示例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) 
開發者ID:airalcorn2,項目名稱:strike-with-a-pose,代碼行數:17,代碼來源:app.py

示例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 
開發者ID:airalcorn2,項目名稱:strike-with-a-pose,代碼行數:8,代碼來源:app.py

示例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 
開發者ID:andrersp,項目名稱:controleEstoque,代碼行數:29,代碼來源:mainprodutos.py


注:本文中的PyQt5.QtCore.QBuffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。