Skip to content

Instantly share code, notes, and snippets.

@driscollis
Last active February 11, 2021 19:53
Show Gist options
  • Save driscollis/42d9cfbb1c642b402128bdc190d80dc9 to your computer and use it in GitHub Desktop.
Save driscollis/42d9cfbb1c642b402128bdc190d80dc9 to your computer and use it in GitHub Desktop.
# kivy_image.py
from kivy.app import App
from kivy.uix.image import Image
class ImageViewer(App):
def build(self):
return Image(source="processed_flower.jpg")
# run the App
ImageViewer().run()
from io import BytesIO
from kivy.app import App
from kivy.core.image import Image as CoreImage
from kivy.uix.image import Image
from PIL import Image as PilImage
class MyApp(App):
def build(self):
image = Image(source="")
pil_image = PilImage.open("processed_flower.jpg")
data = BytesIO()
# Save PIL image to memory
pil_image.save(data, format='png')
# Read the data from memory into new BytesIO object
data.seek(0)
img_data = BytesIO(data.read())
# Update Kivy Image
image.texture = CoreImage(img_data, ext='png').texture
image.reload()
return image
# run the App
MyApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment