iphone - 编辑时如何将图像叠加添加到UIImagePickerControllerSourceTypePhotoLibrary?

标签 iphone ios uiimagepickercontroller

我尝试到处寻找这个问题的答案,但找不到任何有用的信息。

基本上,我希望用户从相册中选择一张图片,然后让应用程序以编辑/裁剪模式显示图片。

在此编辑屏幕上,我想显示一个覆盖屏幕,供用户用来对齐其图像。

然后,他单击“保存”按钮,通过合并图像来保存编辑后的图片和覆盖图像。

我唯一找不到的方法就是在编辑屏幕中添加叠加图像!

在以下情况下我可以很容易地做到这一点:

imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

但是当:

imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

我不能使用:

imagePicker.cameraOverlayView=overlayGraphicView;

这就是我的问题。

此外,如果我添加 UIimage 作为 subview 而不是此叠加层,即使用户从相册中选择其图像,它也会保留在屏幕上。我只希望在选择图像进行编辑之后以及编辑完成后将其保存到相册之前显示叠加层。

感谢您的帮助。

方法如下:

- (IBAction)pickPhotoButton:(id)sender {
    NSLog(@"Pick a Current Photo Button Pressed...");

    // Create image picker controller
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    // Set source to the camera
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    // Delegate is self
    imagePicker.delegate = self;

    // Allow editing of image ?
    imagePicker.allowsEditing = YES;

    // Show image picker
    [self presentModalViewController:imagePicker animated:YES]; 
}

这是我保存到相册的方法:

// Save the image to photo album
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{    
    // Access the uncropped image from info dictionary
    UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"];

    // Combine image with overlay before saving!!
    image = [self addOverlayToImage:image];

    // Save image
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

    [picker release];
}

最佳答案

你可以成为UIImagePickerController对象的委托(delegate)并敏锐地观察UINavigationControllerDelegate方法 - navigationController:didShowViewController:animated: navigationController:willShowViewController:animated: 。您可以知道第二个 View Controller 何时启动,然后将覆盖层添加到 View Controller 的 View 中。示例用法如下所示 –

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if ( [navigationController.viewControllers count] == 2 ) {
        overlayView.center = CGPointMake(135, 135);
        overlayView.bounds = CGRectZero;

        [viewController.view addSubview:overlayView];

        [UIView beginAnimations:@"animateTableView" context:nil];
        [UIView setAnimationDuration:0.4];
        [overlayView setFrame:CGRectMake( 50, 50, 220, 220)];
        [UIView commitAnimations];
    }
}

关于iphone - 编辑时如何将图像叠加添加到UIImagePickerControllerSourceTypePhotoLibrary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6113563/

相关文章:

ios - 如何获取相机ios swift拍摄的照片路径

ios - UIImagePickerController 通过 UIPopoverController

iphone - 如何获取 AVCapture 时间码?

ios - 压缩 UIImage

ios - 我的开发人员退出,如何编辑并继续开发 ipa 文件(Half Built iOS App)

ios - 从 iOS 上的两个不同应用程序访问相同的文件

ios - UICollectionView - 删除所有/清理表

c# - iPhone 应用程序 InputAccessoryView 未出现在 iPad 上

iphone - 核心数据

ios - 从firebase删除 child 后如何更新ios TableView