Last active
February 11, 2021 19:53
-
-
Save driscollis/42d9cfbb1c642b402128bdc190d80dc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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