예제 #1
0
 def image_to_base64(self, img: QImage) -> bytes:
     quality = self.settings.int_value(default_settings.frame_quality)
     byte_arr = QByteArray()
     buffer = QBuffer(byte_arr)
     buffer.open(QIODevice.WriteOnly)
     img.save(buffer, 'jpg', quality)
     return byte_arr.toBase64().data()
예제 #2
0
def encode_image(image: QImage) -> str:
    image_bytes = QByteArray()
    buffer = QBuffer(image_bytes)
    buffer.open(QIODevice.WriteOnly)
    # noinspection PyTypeChecker
    image.save(buffer, "PNG")  # writes pixmap into bytes in PNG format
    encoded_bytes = image_bytes.toBase64()
    encoded_string = encoded_bytes.data().decode()
    return encoded_string
예제 #3
0
def Base64ToBytes(filename):
    image = QImage(filename)
    ba = QByteArray()
    buff = QBuffer(ba)
    image.save(buff, "PNG")
    return ba.toBase64().data()