Forum Archive

Manipulating images from camera

cgallery

I'm trying to take a pic from the camera and display it in the UI without first saving the picture to a roll. So I'm trying to accomplish something similar to this:

raw_photo = photos.pick_image(raw_data=True)
image.image = ui.Image.from_data(raw_photo)

But the camera apparently returns PIL.image object, so I need a way to convert that to something that can be used in the ui?

Any tips here?

I've only been using Pythonista for a few hours and I'm loving it. Addicted, I am.

cvp

Pick_image does not take a photo but allows you to select photo(s) from the camera roll, thus photos already taken.
This method is marked as deprecated in the Doc

Photos.capture_image takes a photo
Please read this topic

And see also photos.Asset.get_ui_image to transform a photo into an ui.Image

omz

@cgallery To convert a PIL.Image to a ui.Image (that can be used with ui.ImageView), you can use something like this:

import io
data_buffer = io.BytesIO()
img.save(data_buffer, 'PNG')
ui_img = ui.Image.from_data(data_buffer.getvalue())
cvp

@omz in your doc you write:
"Assets only contain metadata, so to get an actual image, you’ll have to use the Asset.get_image() function, as shown in the example above. The image is returned as a PIL.Image object. If you want a ui.Image instead, use Asset.get_ui_image()"

omz

@cvp True, but that only applies to assets in the photo library, not to camera images (which aren't necessarily even saved in the photo library).

cvp

@omz ok, Thanks