I copied the code below from the fourm here. I have downloaded a lot of image files from the web using requests lib. They are in .jpg format. I just wanted to know if the code below is as fast as I can make it, or should I open each jpg and write it out as a PNG file instead? Or is there a more native way to store the pics on disk that don't require as much translation when trying to assign them to let's say ui.ImageView.image
f_dir = "/private/var/mobile/Containers/Data/Application/32F49CCB-1015-4E4A-B696-DFC5A77BBEAD/Documents/movie/movie_poster/"
f_name = 'tt2209764.jpeg'
try:
import cStringIO as StringIO
except ImportError:
import StringIO
import ui, Image
def pil_to_ui(img):
# code from pytonista fourms
strio = StringIO.StringIO()
img.save(strio, img.format)
data = strio.getvalue()
strio.close()
return ui.Image.from_data(data)
if __name__ == '__main__':
img = ui.ImageView(frame = (0,0,540,576))
img.image = pil_to_ui(Image.open(f_dir + f_name))
img.present('sheet')