- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我尝试到处寻找这个问题的答案,但找不到任何有用的信息。
基本上,我希望用户从相册中挑选一张图片,然后让应用程序以编辑/裁剪模式显示图片。
在这个编辑屏幕上,我想显示一个覆盖屏幕,供用户用来对齐他的图像。
然后他单击保存按钮,通过合并图像来保存编辑后的图片和叠加图像。
我唯一找不到的方法是在编辑屏幕中添加覆盖图像!
在以下情况下我可以很容易地做到这一点:
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/
有人知道如何在横向模式下显示 UIImagePickerControllerSourceTypePhotoLibrary 就像 iPhone 中的照片应用程序一样吗? - (void)getPho
当我在相机上使用 allowedEditing = NO 时,它工作正常。 作品: if( [UIImagePickerController isSourceTypeAvailable:UIImage
我正在创建一个应用程序,它会在某个时候打开照片库。问题是照片库中的状态栏是黑色透明的,而我想要一个默认的应用程序(纯白色)。有什么办法可以改变它..? 我想补充一点,我试过这个:iOS SDK - H
我目前正在为 iPad 开发一个 iPad 应用程序,我在其中结合使用 UIPopOverController 和 UIImagePickerController 让用户从他们的 iPad 中选择一个
我已经创建了只支持横向方向的应用程序,每当我调用 UIImagePickerControllerSourceTypeCamera 以使用相机拍照时都可以,但是当我调用 UIImagePickerCon
我有一个应用程序允许用户从他们的设备中选择一张照片。为此,我使用了 UIImagePickerController,但问题是我不确定我是否应该使用 UIImagePickerControllerSou
当我升级到 iOS7 时,当我从应用程序访问照片库时,我的应用程序显示一个空的 View Controller 。它正在与旧的框架一起使用。 UIImagePickerController *ima
我有一个 Storyboard,我在其中创建了一个 UINavigationController 实例并将其自定义类设置为 UIImagePickerController。 如果我在 prepareF
我有一个UIActionSheet,其中包含从相机或照片库中选择图像的选项。为此,我采用了imagePickerViewController。对于相机来说,它工作得非常好。但不适用于照片库。 -(vo
我是一名优秀的程序员,十分优秀!