Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Presenting Image.Image in a ui.ImageView
-
I want to display an image in a ui from the camera roll, but I get the error: Expected a ui.Image. How do I convert an image from Image.Image to ui.Image?
Here's what I have so far:
# coding: utf-8 import tempfile, photos, ui @ui.in_background def get_image(sender): view = sender.superview image = view['Image'] try: new = photos.pick_image() new.show() new = new.tostring() image.image = ui.Image.from_data(new) image.image.show() except: view.close() raise view = ui.View(background_color = '#FFFFFF') view.add_subview(ui.Button(name = 'image button', frame = (0,0,80,32))) view['image button'].action = get_image view['image button'].title = 'Set image' view.add_subview(ui.ImageView(name = 'Image', frame = (0,32,80,100))) view.present()
-
Replace the 5 lines between
try
andexcept
with these two lines:raw_photo = photos.pick_image(raw_data=True) image.image = ui.Image.from_data(raw_photo)
-
Perfect, that's exactly what I was looking for, although I ended up implementing it as a one liner:
image.image = ui.Image.from_data(photos.pick_image(raw_data = True))