Ejemplo n.º 1
0
def pixmap_to_data(pixmap, format='PNG'):
    '''
    Return the QPixmap pixmap as a string saved in the specified format.
    '''
    ba = QByteArray()
    buf = QBuffer(ba)
    buf.open(QIODeviceBase.OpenModeFlag.WriteOnly)
    pixmap.save(buf, format)
    return bytes(ba.data())
Ejemplo n.º 2
0
def fromqimage(im):
    """
    :param im: QImage or PIL ImageQt object
    """
    buffer = QBuffer()
    if qt_version == "6":
        try:
            qt_openmode = QIODevice.OpenModeFlag
        except AttributeError:
            qt_openmode = QIODevice.OpenMode
    else:
        qt_openmode = QIODevice
    buffer.open(qt_openmode.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)
Ejemplo n.º 3
0
 def requestStarted(self, rq):
     if bytes(rq.requestMethod()) != b'GET':
         rq.fail(rq.RequestDenied)
         return
     url = rq.requestUrl()
     q = url.path()
     if q == 'downloads':
         rq.reply(b'text/html', QBuffer(get_downloads_html(), self))
     elif q == 'welcome':
         rq.reply(b'text/html', QBuffer(get_welcome_html(), self))
     elif q.startswith('filename-icon/'):
         q = q.partition('/')[2].strip()
         if q:
             rq.reply(b'image/png', QBuffer(filename_icon_data(q), self))
         else:
             rq.fail(rq.UrlNotFound)
     else:
         rq.fail(rq.UrlNotFound)
Ejemplo n.º 4
0
 def _encodeSnapshot(self, snapshot):
     Logger.log("d", "Encoding thumbnail image...")
     try:
         thumbnail_buffer = QBuffer()
         thumbnail_buffer.open(QBuffer.OpenModeFlag.ReadWrite)
         thumbnail_image = snapshot
         thumbnail_image.save(thumbnail_buffer, "PNG")
         base64_bytes = base64.b64encode(thumbnail_buffer.data())
         base64_message = base64_bytes.decode('ascii')
         thumbnail_buffer.close()
         return base64_message
     except Exception:
         Logger.logException("w", "Failed to encode snapshot image")
Ejemplo n.º 5
0
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()
    qt_openmode = QIODevice.OpenMode if qt_version == "6" else QIODevice
    buffer.open(qt_openmode.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)
Ejemplo n.º 6
0
 def update_output(self, index, buffer: qtc.QBuffer):
     if index == None or buffer == None or index < 0 or index - 1 > len(self._frames):
         return
     output = Image.open(io.BytesIO(buffer.data()))
     self._frames[index].set_output(output)