Python PySide2.QtCore.QBuffer() Examples

The following are 9 code examples of PySide2.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 PySide2.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 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) 
Example #2
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 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) 
Example #3
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 #4
Source File: ImageQt.py    From FODI with GNU General Public License v3.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 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) 
Example #5
Source File: utils.py    From pivy with ISC License 5 votes vote down vote up
def add_marker_from_svg(file_path, marker_name, pixel_x=10, pixel_y=None,
                     isLSBFirst=False, isUpToDown=False):
    """adds a new marker bitmap from a vector graphic (svg)"""

    # get an icon from the svg rendered with the given pixel
    from PySide2 import QtCore, QtGui
    pixel_y = pixel_y or pixel_x
    icon = QtGui.QIcon(file_path)
    icon = QtGui.QBitmap(icon.pixmap(pixel_x, pixel_y))

    # create a XMP-icon
    buffer=QtCore.QBuffer()
    buffer.open(buffer.WriteOnly)
    icon.save(buffer,"XPM")
    buffer.close()

    # get a string from the XMP-icon
    ary = str(buffer.buffer(), "utf8")
    ary = ary.split("\n", 1)[1]
    ary = ary.replace('\n', "").replace('"', "").replace(";", "")
    ary = ary.replace("}", "").replace("#", "x").replace(".", " ")
    string = str.join("", ary.split(",")[3:])
    
    # add the new marker style
    setattr(coin.SoMarkerSet, marker_name, coin.SoMarkerSet.getNumDefinedMarkers())
    coin.SoMarkerSet.addMarker(getattr(coin.SoMarkerSet, marker_name), 
                               coin.SbVec2s([pixel_x, pixel_y]), string,
                               isLSBFirst, isUpToDown) 
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: 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 #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 FODI with GNU General Public License v3.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)