我正在使用带有剪切的透明图片供用户插入/拍摄自己的图片。出于某种原因,在使用UIImagePickerControllerEditedImage
并裁剪用户拍摄的照片时,图像不会像编辑时那样保存;例如,见照片。
我的问题是图片无法准确保存照片的编辑方式。 (即:裁剪/调整大小)。
-(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 );
}
同样,编辑“裁剪”部分还有白色空格,如下所示:
答案 0 :(得分:1)
我认为这是因为编辑后的照片不包含被半透明取景叠加遮挡的部分,这些部分显示为标准iOS图像编辑器的一部分。 (您发现必须偏移的60px是此叠加层上半部分的60px。)
您可以从UIImagePickerControllerCropRect
词典中提取并展开info
键,然后在UIImagePickerControllerOriginalImage
上自行重新编辑,以获得您想要的结果图像。