国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

IOS UIImagePickerController從拍照、圖庫、相冊獲取圖片

2019-10-21 18:44:26
字體:
供稿:網(wǎng)友

IOS UIImagePickerController從拍照、圖庫、相冊獲取圖片

iOS 獲取圖片有三種方法:

1. 直接調(diào)用攝像頭拍照

2. 從相冊中選擇

3. 從圖庫中選擇

UIImagePickerController 是系統(tǒng)提供的用來獲取圖片和視頻的接口;

用UIImagePickerController 類來獲取圖片視頻,大體分為以下幾個步驟:

1. 初始化UIImagePickerController 類;

2. 設(shè)置UIImagePickerController 實例的數(shù)據(jù)來源類型(下面解釋);

3. 設(shè)置設(shè)置代理;

4. 如果需要做圖片修改的話設(shè)置allowsEditing =yes。

數(shù)據(jù)來源類型一共有三種:

enum {  UIImagePickerControllerSourceTypePhotoLibrary ,//來自圖庫  UIImagePickerControllerSourceTypeCamera ,//來自相機  UIImagePickerControllerSourceTypeSavedPhotosAlbum //來自相冊};

在用這些來源的時候最好檢測以下設(shè)備是否支持;

 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])  {    NSLog(@"支持相機");  }  if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])  {    NSLog(@"支持圖庫");  }  if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])  {    NSLog(@"支持相片庫");  }

調(diào)用攝像頭來獲取資源

- (void)viewDidLoad {  [super viewDidLoad];  picker = [[UIImagePickerController alloc]init];  picker.view.backgroundColor = [UIColor orangeColor];  UIImagePickerControllerSourceType sourcheType = UIImagePickerControllerSourceTypeCamera;  picker.sourceType = sourcheType;  picker.delegate = self;  picker.allowsEditing = YES;}

上面只是實例了UIImagePickerController及其屬性 在需要獲取圖片的時候需要彈出窗口調(diào)用

[self presentViewController:picker animated:YES completion:nil];

我們還需要代理來獲取我們選中的圖片

UIImagePickerControllerDelegate

代理中一共三個方法 其中一個3.0 已經(jīng)廢棄了,只剩下兩個我們需要用的

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;

當用戶選取完成后調(diào)用;

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;

當用戶取消選取時調(diào)用;

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;

選取的信息都在info中,info 是一個字典。

字典中的鍵:

NSString *const UIImagePickerControllerMediaType ;指定用戶選擇的媒體類型(文章最后進行擴展)NSString *const UIImagePickerControllerOriginalImage ;原始圖片NSString *const UIImagePickerControllerEditedImage ;修改后的圖片NSString *const UIImagePickerControllerCropRect ;裁剪尺寸NSString *const UIImagePickerControllerMediaURL ;媒體的URLNSString *const UIImagePickerControllerReferenceURL ;原件的URLNSString *const UIImagePickerControllerMediaMetadata;當來數(shù)據(jù)來源是照相機的時候這個值才有效

UIImagePickerControllerMediaType 包含著KUTTypeImage 和KUTTypeMovie

KUTTypeImage 包含:

const CFStringRef kUTTypeImage ;抽象的圖片類型const CFStringRef kUTTypeJPEG ;const CFStringRef kUTTypeJPEG2000 ;const CFStringRef kUTTypeTIFF ;const CFStringRef kUTTypePICT ;const CFStringRef kUTTypeGIF ;const CFStringRef kUTTypePNG ;const CFStringRef kUTTypeQuickTimeImage ;const CFStringRef kUTTypeAppleICNS const CFStringRef kUTTypeBMP;const CFStringRef kUTTypeICO;

KUTTypeMovie 包含:

const CFStringRef kUTTypeAudiovisualContent ;抽象的聲音視頻const CFStringRef kUTTypeMovie ;抽象的媒體格式(聲音和視頻)const CFStringRef kUTTypeVideo ;只有視頻沒有聲音const CFStringRef kUTTypeAudio ;只有聲音沒有視頻const CFStringRef kUTTypeQuickTimeMovie ;const CFStringRef kUTTypeMPEG ;const CFStringRef kUTTypeMPEG4 ;const CFStringRef kUTTypeMP3 ;const CFStringRef kUTTypeMPEG4Audio ;const CFStringRef kUTTypeAppleProtectedMPEG4Audio;

如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!


注:相關(guān)教程知識閱讀請移步到IOS開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 山丹县| 密云县| 鄂伦春自治旗| 仪陇县| 东乡族自治县| 河源市| 含山县| 郧西县| 盐山县| 广安市| 青州市| 怀柔区| 鄂伦春自治旗| 曲麻莱县| 合水县| 滦平县| 浦东新区| 屯昌县| 苗栗县| 杭锦后旗| 景德镇市| 固原市| 安陆市| 安溪县| 行唐县| 桃园市| 厦门市| 拉萨市| 武穴市| 定边县| 通州区| 北安市| 长治市| 万宁市| 阿城市| 阜城县| 唐山市| 苍溪县| 岳西县| 昔阳县| 娱乐|