简体   繁体   中英

allowEditing property of UIImagePickerController creating issues

I'm trying to take image using UIImagePickerController. If the property allowEditing is NO then everything working fine. But as soon as I change the property value to YES no image is coming. It's occuring in both Camera and Library.

Below is the code that executed when button is tapped for opening camera.

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        UIImagePickerController *controller_imagePicker = [[UIImagePickerController alloc] init];
        [controller_imagePicker setDelegate:self];
        [controller_imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
        [controller_imagePicker setAllowsEditing:YES];
        controller_imagePicker.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        [self presentViewController:controller_imagePicker animated:YES completion:nil];
    }

And when we take the image and edits it and use the image. black image is coming in the respecitve imageview.

Also as soon as the camera opens I receive this warning: "Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates."

Any Idea??

You should use UIImagePickerControllerEditedImage key instead of UIImagePickerControllerOriginalImage if allowsEditing.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *image = nil;
    if ([picker allowsEditing]){
        image = [info objectForKey:UIImagePickerControllerEditedImage];
    } else {
        image = [info objectForKey:UIImagePickerControllerOriginalImage];
    }
    // do something
}
#import <MobileCoreServices/UTCoreTypes.h>
….
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    UIImagePickerController *imagePickerCamera =[[UIImagePickerController alloc] init];
    imagePickerCamera.delegate = self;
    imagePickerCamera.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
    imagePickerCamera.allowsEditing = YES;
    imagePickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:imagePickerCamera  animated:YES completion:nil];
}

else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
    UIImagePickerController *imagePickerAlbum =[[UIImagePickerController alloc] init];
    imagePickerAlbum.delegate = self;
    imagePickerAlbum.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
    imagePickerAlbum.allowsEditing = YES;
    imagePickerAlbum.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentViewController:imagePickerAlbum animated:YES completion:nil];
}


#pragma mark - ImagePickerController Delegate

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) {
        [picker dismissViewControllerAnimated:YES completion:nil];
    }
    else
    {
        [popover dismissPopoverAnimated:YES];
    }


    UIImage* originalImage = nil;
    originalImage = [info objectForKey:UIImagePickerControllerEditedImage];

    if(originalImage==nil)
    {
        originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    }

    if(originalImage==nil)
    {
        originalImage = [info objectForKey:UIImagePickerControllerCropRect];
    }
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM