编辑时如何将图像叠加到 UIImagePickerControllerSourceTypePhotoLibrary 中?
我尝试到处寻找这个问题的答案,但找不到任何有用的信息。
基本上,我希望用户从相册中选择一张图片,然后让应用程序以编辑/裁剪模式显示图片。
在此编辑屏幕上,我想显示一个覆盖屏幕,供用户用来对齐其图像。
然后,他单击“保存”按钮,通过合并图像来保存编辑后的图片和覆盖图像。
我唯一找不到如何做的就是在编辑屏幕中添加叠加图像!
在以下情况下我可以很容易地做到这一点:
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
但是当:
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
我无法使用:
imagePicker.cameraOverlayView = overlayGraphicView;
这就是我的问题。
另外,如果我添加 UIimage 作为子视图而不是此叠加层,即使用户从相册中选择他的图像,它也会保留在屏幕上。我只希望在选择图像进行编辑之后以及编辑完成后将其保存到相册之前显示叠加层。
感谢您的帮助。
方法如下:
- (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];
}
I've tried looking everywhere for an answer to this but can not find any useful info.
Basically, I want the user to pick a picture from the album, and then have the app display the picture in the edit/crop mode.
On this edit screen I want to display an overlay screen for the user to use to align his image.
He then clicks the save button which saves the edited picture with the overlay image by just merging the images.
The only thing I can not find how to do is add the overlay image in the edit screen!
I can do this quite easily when:
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
But when:
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
I can not use:
imagePicker.cameraOverlayView = overlayGraphicView;
and that is my issue.
Also if I add an UIimage as a subview instead then this overlay, it stays on the screen even when the user is choosing his image from the album. I only want the overlay to appear after the image has been chosen for editing and before it has been saved to the album after the editing has finished.
Thanks for your help.
Heres the method:
- (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];
}
and heres my save to album method:
// 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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以成为 UIImagePickerController 对象的委托并敏锐地观察 UINavigationControllerDelegate 方法 -
navigationController:didShowViewController:animated:
和navigationController:willShowViewController:animated:
。您可以知道第二个视图控制器何时启动,然后将覆盖层添加到视图控制器的视图中。示例用法如下所示 –You can become
UIImagePickerController
object's delegate and keenly observe theUINavigationControllerDelegate
methods -navigationController:didShowViewController:animated:
andnavigationController:willShowViewController:animated:
. You can know when the second view controller is coming on and later add your overlay to the view controller's view. Sample usage is shown below –您可以使用以下自定义方法将叠加层添加到 Imagepickercontroller
在您的classname
.h
文件中定义You can use the following customised method for adding overlays to the Imagepickercontroller
In yourclassname
.h
file define