@superrune , this is not your full answer. But the below is something I did some time ago. I think for the write, gives you an idea. Not sure you are on the beta program or not. But if you are on the beta program the file would be saved to Icloud as the path will exist. Otherwise it will create the image in the script dir.
This example renders a simple image to a ui.View, console and writes the image to a file. Does not do the read. But this is a basic framework.
import ui
import os.path
icloud_path='/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/'
class DrawSomething(ui.View):
rect = (0, 0, 200, 200)
def draw(self):
self.my_draw()
def my_draw(self):
with ui.GState():
ui.set_color('deeppink')
shape = ui.Path.rect(*self.rect)
shape.fill()
def image_get(self):
with ui.ImageContext(self.rect[2], self.rect[3]) as ctx:
self.my_draw()
img = ctx.get_image()
return img
def image_save(self, path):
img = self.image_get()
with open(path, 'wb') as file:
file.write(img.to_png())
if __name__ == '__main__':
img_fn = 'junk.png'
if os.path.exists(icloud_path):
img_fn = os.path.join(icloud_path, img_fn)
ds = DrawSomething()
ds.present('sheet')
ds.image_save(img_fn)
ds.image_get().show()
print(img_fn)