[Question] Image widget loading from BytesIO

61 views
Skip to first unread message

Xan Krigor

unread,
Aug 21, 2018, 6:27:05 PM8/21/18
to Kivy users support
Hello! I have a question and partially don't understand if I can load image to widget from my ByteIO variable. The documentation have only variations: Image and AsyncImage what can load image from file (string) or url (string), but what about ByteIO object?

There is no way I can save image on the disk because I load images in a batch and keep for short time in memory, frequently update it (in Pillow) and replace and there also not possible to use direct AsyncImage because I make request from a session (signed and use cookies with different header and proxy).

Gabriel Pettier

unread,
Aug 26, 2018, 12:50:30 PM8/26/18
to kivy-...@googlegroups.com
I needed that some time ago, and could only find solutions that used the
pygame loader, which was sad, but this worked with the PIL/Pillow one.


img being an Image object from Pillow.

data = BytesIO()
img.save(data, format='png')
data.seek(0)
image = ImageLoaderPIL(
'__inline__', ext='png', rawdata=data, inline=True, nocache=True
)

Hope this helps.

On Tue, Aug 21, 2018 at 03:27:04PM -0700, Xan Krigor wrote:
>Hello! I have a question and partially don't understand if I can load image
>to widget from my ByteIO variable. The documentation
><https://kivy.org/docs/api-kivy.uix.image.html> have only variations: Image
>and AsyncImage what can load image from file (string) or url (string), but
>what about ByteIO object?
>
>There is no way I can save image on the disk because I load images in a
>batch and keep for short time in memory, frequently update it (in Pillow)
>and replace and there also not possible to use direct AsyncImage because I
>make request from a session (signed and use cookies with different header
>and proxy).
>
>--
>You received this message because you are subscribed to the Google Groups "Kivy users support" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
>To post to this group, send email to kivy-...@googlegroups.com.
>Visit this group at https://groups.google.com/group/kivy-users.
>To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d5aeb36e-17d3-4eb1-b515-d92b958700ae%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages