Python PySide.QtCore.QBuffer() Examples

The following are 10 code examples of PySide.QtCore.QBuffer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PySide.QtCore , or try the search function .
Example #1
Source File: ImageQt.py    From teleport with Apache License 2.0 6 votes vote down vote up
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) 
Example #2
Source File: ImageQt.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #3
Source File: ImageQt.py    From lambda-text-extractor with Apache License 2.0 6 votes vote down vote up
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) 
Example #4
Source File: ImageQt.py    From lambda-text-extractor with Apache License 2.0 6 votes vote down vote up
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) 
Example #5
Source File: utils.py    From FreeCAD_assembly3 with GNU General Public License v3.0 5 votes vote down vote up
def getIcon(obj,disabled=False,path=None):
    if not path:
        path = iconPath
    if not getattr(obj,'_icon',None):
        obj._icon = addIconToFCAD(obj._iconName,path)
    if not disabled:
        return obj._icon
    if not getattr(obj,'_iconDisabled',None):
        name = getattr(obj,'_iconDisabledName',None)
        if name:
            obj._iconDisabled = addIconToFCAD(name,path)
        else:
            key = os.path.join(path,obj._iconName) + '.disabled'
            fmt = None
            try:
                if FreeCADGui.isIconCached(key):
                    obj._iconDisabled = key
                    return key
                else:
                    fmt = 'PNG'
            except Exception:
                pass
            pixmap = FreeCADGui.getIcon(obj._icon).pixmap(*iconSize,mode=QIcon.Disabled)
            icon = QIcon(pixmapDisabled)
            icon.paint(QPainter(pixmap),0,0,iconSize[0],iconSize[1],Qt.AlignCenter)
            data = QByteArray()
            buf = QBuffer(data)
            buf.open(QIODevice.WriteOnly)
            if fmt:
                pixmap.save(buf, fmt)
                FreeCADGui.addIcon(key,data.data(),fmt)
            else:
                pixmap.save(buf, 'XPM')
                key = data.data().decode('latin1')
            obj._iconDisabled = key
    return obj._iconDisabled 
Example #6
Source File: ImageQt.py    From teleport with Apache License 2.0 5 votes vote down vote up
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) 
Example #7
Source File: heatmap.py    From heatmappy with MIT License 5 votes vote down vote up
def _qimage_to_pil_image(qimg):
        buffer = QtCore.QBuffer()
        buffer.open(QtCore.QIODevice.ReadWrite)
        qimg.save(buffer, "PNG")

        bytes_io = io.BytesIO()
        bytes_io.write(buffer.data().data())
        buffer.close()
        bytes_io.seek(0)
        return Image.open(bytes_io) 
Example #8
Source File: ImageQt.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #9
Source File: ImageQt.py    From lambda-text-extractor with Apache License 2.0 5 votes vote down vote up
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) 
Example #10
Source File: ImageQt.py    From lambda-text-extractor with Apache License 2.0 5 votes vote down vote up
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)