Forum Archive

Image.from_data() not a method?

TutorialDoctor

I am trying to load an image from the camera roll as the background of a button.

from PIL import Image
import ui
import photos



window = ui.load_view()
window.present('sheet')

window['button'].background_image = Image.from_data(photos.get_image(-1,True,True))

What am I doing wrong? It says that from_data is not a method

omz

Try ui.Image.from_data() instead. Image alone refers to PIL in your script.

TutorialDoctor

Thanks once again Ole, haha. Don't worry, I am actually using this information for a useful purpose.

I have been wanting to use local images in the Imageview control for the longest (not an option in the Custom UI action) so I finally dug into the modules a bit.

Now I can load these images in:

from PIL import Image
import ui
import photos

window = ui.load_view()
window.present('sheet')

image = ui.Image.from_data(photos.pick_image(True,False,True,True,False))


window['view'].image = image

Now to animate...