Simple Imageview help
I want to try to get the following example working. The goal is to have a picture be a sub-view of a scroll view. Why doesn't the following example work?
import ui import Image sv = ui.ScrollView() sv.background_color = 'gray' im = Image.open('Test_Boat') iv = ui.ImageView() iv.image = im sv.add_subview(iv) sv.present()```
If you change your Image.open
im = ui.Image.named('Test_Boat')
It should work
uiuses a different image class than
PIL. To convert PIL images to UI, I typically use:
def pil_to_ui(img): b = BytesIO() img.save(b, "PNG") data = b.getvalue() b.close() return ui.Image.from_data(data)
That function takes a PIL image as input, and returns a ui.Image as output.
Thanks Phuket2. It worked well. I did not see
ui.Image.named()in the Pythonista documentation so I did not know that existed.
Actually named.image is in the documentation, ui.Image class. In this case I think it's more about examples. I had a hard time with this also before