Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load image from memory in Kivy

I have a picture in memory a format (output from pyplot) and I want to directly show it on the Android through Kivy, but I don't want to create a picture file. Is there any way to do this? On pyplot I am able to generate the file like object by writing it the object, but I don't know how to put it into Kivy.

like image 835
Snakes and Coffee Avatar asked May 25 '12 23:05

Snakes and Coffee


People also ask

What is texture in KIVY?

Texture is a class that handles OpenGL textures. Depending on the hardware, some OpenGL capabilities might not be available (BGRA support, NPOT support, etc.) You cannot instantiate this class yourself. You must use the function Texture.create() to create a new texture: texture = Texture.

What is a widget in KIVY?

A Widget is the base building block of GUI interfaces in Kivy. It provides a Canvas that can be used to draw on screen. It receives events and reacts to them. For a in-depth explanation about the Widget class, look at the module documentation.


1 Answers

Similar to the first answer but doesn't require img_pygame:

    from kivy.core.image import Image as CoreImage
    from kivy.uix.image import Image
    import io
    import qrcode # specific to my usecase, interchangeable with Pil.Image
    # OR
    from PIL import Image as PilImage


    msg = "text"
    image = Image(source="")
    imgIO = io.BytesIO()
    qr = qrcode.make(msg) # returns PilImage object
    qr.save(imgIO, ext='png') # equivalent to Pil.Image.save()
    imgIO.seek(0)
    imgData = io.BytesIO(imgIO.read())
    image.texture = CoreImage(imgData, ext='png').texture
    image.reload()
like image 122
iohzrd Avatar answered Sep 19 '22 08:09

iohzrd