带有用户照片的相机叠加层未按编辑后保存

发布于 2024-11-29 11:35:36 字数 2118 浏览 3 评论 0原文

我使用带有剪切的透明图像,供用户插入/拍摄自己的图像。由于某种原因,在使用 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 );       
}

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

在此处输入图像描述

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅笑轻吟梦一曲 2024-12-06 11:35:36

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文