Camera Overlay with User-Photo not saving as edited
Asked Answered
S

1

21

I am using a transparent image with a cut out for a user to insert / take their own image. For some reason, while using the UIImagePickerControllerEditedImage and cropping the user-taken photo, the image does not save as it was edited; see photo for example.

My issue is that the image does not save exactly how the photo was edited. (i.e: cropped / resized).

Setting up the UIImagePicker

-(void)choosePhotoDialog:(id)sender
{        
    OverlayView * overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH_IPHONE, SCREEN_HEIGTH_IPHONE) andPhoto:[dict objectForKey:@"imageUrl"]];
    [overlay setUserInteractionEnabled: NO];

    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    [picker setSourceType: UIImagePickerControllerSourceTypeCamera];
    [picker setDelegate: self];
    [picker setAllowsImageEditing: YES];
    [picker setShowsCameraControls: YES];
    [picker setNavigationBarHidden: YES];
    [picker setWantsFullScreenLayout: YES];
    [picker setCameraOverlayView: overlay];
    [self presentModalViewController:picker animated:YES];  
    [picker release];
}

After the image is edited:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    SDWebImageManager * manager = [SDWebImageManager sharedManager];
    UIImage * cachedImage  = [manager imageWithURL: [NSURL URLWithString: @"http://www.someurl.com/test.png"]];
    UIImage * userOriginal = [info valueForKey:UIImagePickerControllerEditedImage];

    /*  combining the overlay and the user-photo  */
    UIGraphicsBeginImageContext( CGSizeMake(640,960) );

        /*  for some reason I have to push the user-photo
            down 60 pixels for it to show correctly as it
            was edited.
         */
        [userOriginal drawAtPoint:CGPointMake(0,60)];
        [cachedImage drawAtPoint:CGPointMake(0,0)];

        UIImage * draft = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum( draft, self, @selector(image:didFinishSavingWithError:contextInfo:), nil );       
}

As well, there are white spaces from the editing "crop" portion as demonstrated in the following:

enter image description here

Sadoc answered 16/8, 2011 at 0:51 Comment(7)
I was able to find another answer on S.O. that helped me with this. #1260749Sadoc
WrightsCS, could you maybe add an answer to this question and then mark it as accepted (not an abuse of SO)? That way people who find this in the future can see how you solved it.Magnetograph
@Terry, You cannot post answers to your own questions now on S.O. Just adds it as a comment, sorry.Sadoc
I answered my own question just a couple weeks back. Is this something new?Magnetograph
I believe so, because when I go to "answer" the question, it adds it as a comment instead.Sadoc
If you give a very short answer to your own question it will turn it into a comment.Azygous
If you give a short answer to someone else's question it will also turn it into a comment. @WrightsCS, try writing more of a description of how that other question helped you resolve your problem.Deliquescence
S
1

I believe this is because the edited photo does not include the parts obscured by the semi-transparent framing overlay that is shown as part of the standard iOS image editor. (The 60px you've found you must offset by is the 60px of the top half of this overlay.)

You can extract and expand the UIImagePickerControllerCropRect key from the info dictionary and do the edit again yourself on the UIImagePickerControllerOriginalImage in order to get the resultant image you desire.

Scalf answered 25/10, 2011 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.