Injectios
Injectios

Reputation: 2797

How can I set a custom image in UIIMagePickerController

I have UIActionSheet with 3 options -

  1. Take a photo (from camera)
  2. Choose from library
  3. Edit photo (if user has profile picture )

I use UIImagePickerController and don't have problems with first 2 options. User choose photo and then can zoom/move to crop one.

So, my question is - how I can put already saved photo for editing (3rd option) with current scale factor and frame. F.e if I choose "edit photo" I want to get the same photo "state" that I've choosen after preview.

That is how native "contacts" app works!

photo's preview

Upvotes: 0

Views: 1181

Answers (1)

coneybeare
coneybeare

Reputation: 33101

You need to access the UIImagePickerControllerEditedImage object in your delegate method:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    if (!image) image = [info objectForKey:UIImagePickerControllerOriginalImage];
    ....
}

Then you can use this image in your own edit view controller. The Contacts app works this way because it writes the edited image back to the ALAsset, a destructive change. It is probably a bad idea to do this for users in your app, so it is best to write your own edit image controller that will handle the edited image instead of UIImagePickerController. A search on github shows tons of open-source repos that can help you with cropping here.

Upvotes: 1

Related Questions