Forum Archive

'Image' instance displayed in Draw method of ui.View??

Bruce42

So, I thought I posted this earlier today, but it's not there now. Don't know if I didn't complete the posting or if it was removed because of some rules I'm unaware of. Anyway, here goes again.

Using the new method of the Image module I can creat what I want. I can combine images using the paste method. I can display the combined images in the council with the show() method.

But I want to display the images using the draw method of ui.View.

Is there a simple way to do this without first saving the images to disc?

JonB

The PIL.Image object can be converted to ui.Image.

See https://omz-forums.appspot.com/pythonista/post/5520750224080896

The pil2ui in jmv38's final post uses a bytesIO object (which is file-like, but in memory).

Bruce42

Thanks JonB.
This works.
There is some strange scaling going on if my ui.View has a width and/or height different from that of the pil Image. I don't understand that part of it yet but you've moved me well along my way. Thanks!

JonB

There is a content_mode scaling parameter in a view, which controls what happens when you size a view differently from the native image.

If you don't want the aspect ratio to change, you'd use ui.CONTENT_SCALE_ASPECT_FIT or ui.CONTENT_SCALE_ASPECT_FILL, or maybe even one of the ui.CONTENT_TOP_LEFT style.

You can also auto-resize the view that shows the image using size_to_fit, which might make sense in some cases.