如何允许用户从他的相机胶卷或照片库中挑选照片? [英] How to allow the user to pick a photo from his camera roll or photo library?
问题描述
我正在制作一个有趣的照片编辑应用程序.用户必须从他们的相机胶卷中选择一张照片,然后将其导入以进行修改.
I'm making a little photo editing app for fun. Users must select a photo from their camera roll which will then be imported for modification.
这通常是如何工作的?我见过许多应用程序允许使用看起来始终相同的标准控制器.
How does this generally work? I have seen many apps allowing this with a standard controller that looks always the same.
是否也可以直接访问该库或自定义该控制器的外观?
Is it also possible to access this library directly or to customize the appearance of that controller?
我应该从哪里开始寻找?
Where should I start looking?
推荐答案
我开发了一个允许用户选择个人图像的应用程序.我有两个 UIButtons 可以帮助用户选择图片,无论是来自相机还是图书馆.是这样的:
I worked on an application that allows user to select a personal image. I had two UIButtons which could help the user to pick a picture, whether it was from camera or library. It's something like this:
- (void)camera {
if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
return;
}
UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Permetto la modifica delle foto
picker.allowsEditing = YES;
//Imposto il delegato
[picker setDelegate:self];
[self presentModalViewController:picker animated:YES];
}
- (void)library {
//Inizializzo la classe per la gestione della libreria immagine
UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//Permetto la modifica delle foto
picker.allowsEditing = YES;
//Imposto il delegato
[picker setDelegate:self];
[self presentModalViewController:picker animated:YES];
}
你必须实现 UIImagePickerControllerDelegate:
You have to implement the UIImagePickerControllerDelegate:
@interface PickPictureViewController : UIViewController <UIImagePickerControllerDelegate>
@implementation PickPictureViewController
#pragma mark UIImagePickerController Delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *pickedImage = [info objectForKey:UIImagePickerControllerEditedImage];
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(pickedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissModalViewControllerAnimated:YES];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{}
希望对您有所帮助!;)
Hope it helps! ;)
这篇关于如何允许用户从他的相机胶卷或照片库中挑选照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!