用户照片的相机叠加未保存为已编辑

Wri*_*sCS 21 uiimagepickercontroller uiimage cgimage ios camera-overlay

我正在使用带有剪切的透明图像,以便用户插入/拍摄自己的图像.出于某种原因,在使用UIImagePickerControllerEditedImage和裁剪用户拍摄的照片时,图像不会像编辑时那样保存; 比如看照片.

我的问题是图像没有准确保存照片的编辑方式.(即:裁剪/调整大小).

设置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];
}
Run Code Online (Sandbox Code Playgroud)

编辑图像后:

- (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 );       
}
Run Code Online (Sandbox Code Playgroud)

同样,有白色脱离如显示于以下编辑"作物"部位:

在此输入图像描述

Ben*_*jie 1

我相信这是因为编辑后的照片不包括被半透明框架覆盖层遮挡的部分,该覆盖层显示为标准 iOS 图像编辑器的一部分。(您发现必须偏移的 60 像素是该叠加层上半部分的 60 像素。)

UIImagePickerControllerCropRect您可以从字典中提取并扩展密钥info,然后自己再次进行编辑,以UIImagePickerControllerOriginalImage获得您想要的结果图像。