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

时间:2011-08-16 00:51:08

标签: ios uiimage uiimagepickercontroller cgimage 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];
}

编辑图像后:

- (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 );       
}

同样,编辑“裁剪”部分还有白色空格,如下所示:

enter image description here

1 个答案:

答案 0 :(得分:1)

我认为这是因为编辑后的照片不包含被半透明取景叠加遮挡的部分,这些部分显示为标准iOS图像编辑器的一部分。 (您发现必须偏移的60px是此叠加层上半部分的60px。)

您可以从UIImagePickerControllerCropRect词典中提取并展开info键,然后在UIImagePickerControllerOriginalImage上自行重新编辑,以获得您想要的结果图像。