系统相冊和拍照
Posted jzdwajue
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了系统相冊和拍照相关的知识,希望对你有一定的参考价值。
1.系统相冊和拍照
//有系统预置的多媒体參数
#import <MobileCoreServices/MobileCoreServices.h>
UIImagePickerController 拍照和获取系统相冊
推断是否支持
BOOL ret = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//设置资源类型
imagePicker.sourceType = type;
//设置代理
imagePicker.delegate = self;
//是否同意对相冊 等做兴许处理
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:^{
}];
#pragma mark - UIImagePickerControllerDelegate
//点击picker上的cancelbutton时,触发的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
NSLog(@"cancel!!");
//实现picker的dismiss
[picker dismissViewControllerAnimated:YES completion:^{
}];
}
//点击choosebutton触发的方法
//info 带有选中资源的信息
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//推断选中的资源的类型
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
//kUTTypeImage 系统预置的图片资源类型
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
//证明取出来的是图片
//通过字典获取选中的图片
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
//从相机中取出来的图片占的空间:(1M-2M)左右,须要对图片进行压缩处理,然后在进行兴许操作
//将原图压缩成50*50的尺寸
UIImage *smallImage = [[ImageTool shareTool] resizeImageToSize:CGSizeMake(50,50) sizeOfImage:image];
self.view.backgroundColor = [UIColor colorWithPatternImage:smallImage];
}
[picker dismissViewControllerAnimated:YES completion:^{
}];
}
//有系统预置的多媒体參数
#import <MobileCoreServices/MobileCoreServices.h>
UIImagePickerController 拍照和获取系统相冊
推断是否支持
BOOL ret = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//设置资源类型
imagePicker.sourceType = type;
//设置代理
imagePicker.delegate = self;
//是否同意对相冊 等做兴许处理
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:^{
}];
#pragma mark - UIImagePickerControllerDelegate
//点击picker上的cancelbutton时,触发的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
NSLog(@"cancel!!");
//实现picker的dismiss
[picker dismissViewControllerAnimated:YES completion:^{
}];
}
//点击choosebutton触发的方法
//info 带有选中资源的信息
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//推断选中的资源的类型
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
//kUTTypeImage 系统预置的图片资源类型
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
//证明取出来的是图片
//通过字典获取选中的图片
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
//从相机中取出来的图片占的空间:(1M-2M)左右,须要对图片进行压缩处理,然后在进行兴许操作
//将原图压缩成50*50的尺寸
UIImage *smallImage = [[ImageTool shareTool] resizeImageToSize:CGSizeMake(50,50) sizeOfImage:image];
self.view.backgroundColor = [UIColor colorWithPatternImage:smallImage];
}
[picker dismissViewControllerAnimated:YES completion:^{
}];
}
以上是关于系统相冊和拍照的主要内容,如果未能解决你的问题,请参考以下文章
Android调用相机实现拍照并裁剪图片,调用手机中的相冊图片并裁剪图片