UIImagePickerController
● 使用UIImagePickerController就可以进行拍照或者读取相册
● 通过sourceType属性来决定拍照还是读取相册
➢ UIImagePickerControllerSourceTypeCamera 相机
➢ UIImagePickerControllerSourceTypePhotoLibrary 相册
● 通过sourceType属性来决定拍照还是读取相册
➢ UIImagePickerControllerSourceTypeCamera 相机
➢ UIImagePickerControllerSourceTypePhotoLibrary 相册
拍照-相册示例
UIImagePickerController *picker = [[UIImagePickerController
alloc] init];
switch (buttonIndex) {
case 0:
// 拍照 picker.sourceType =
UIImagePickerControllerSourceTypeCamera;
break;
case 1:
// 相册
picker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
break; }
// 设置代理
picker.delegate = self;
// 展示控制器
[self presentViewController:picker animated:YES completion:nil];
拍照-相册代理方法
● 拍照或者从相册取图片完毕后,就会通知代理
- (void)imagePickerController:(UIImagePickerController *)picker
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
_imageView.image =
info[UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:nil]; }
添加图片到系统相册中
UIImageWriteToSavedPhotosAlbum([UIImage
imageNamed:@"Default.png"], self,
@selector(image:didFinishSavingWithError:contextInfo:),
NULL);
● 另外,有个UISaveVideoAtPathToSavedPhotosAlbum函数可以导入视频到相册 中