欢迎来到天天文库
浏览记录
ID:62033460
大小:24.00 KB
页数:3页
时间:2021-04-15
《iOS从相机或相册获取图片并裁剪.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、iOS从相机或相册获取图片并裁剪需要从相册或者相机中读取图片.代码很简单,抽取关键部分,如下: //loaduserimage-(void)UesrImageClicked{ UIActionSheet*sheet; // 判断是否支持相机if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {sheet= [[UIActionSheetalloc]initWithTitle:@"
2、选择图像”delegate:selfcancelButtonTitle:nildestructiveButtonTitle:@"取消"otherButtonTitles:@"拍照",@”从相册选择”, nil]; }else{ sheet= [[UIActionSheetalloc]initWithTitle:@"选择图像” delegate:selfcancelButtonTitle:nil destructiveButtonTitle:@"取消" otherButtonTitles:@"从相册选择”,nil];
3、} sheet.tag=255;[sheetshowInView:self.view];}#pragmamark— action sheetdelegte—(void)actionSheet:(UIActionSheet *)actionSheetclickedButtonAtIndex:(NSInteger)buttonIndex{ if(actionSheet.tag==255){NSUIntegersourceType= UIImagePickerControllerSourceTypePhotoLibrary
4、; //判断是否支持相机 if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ switch (buttonIndex){ case 0: return; case 1://相机 sourceType = UIImagePickerControllerSourceTypeCamera; break; case2: //相册 sourceTyp
5、e=UIImagePickerControllerSourceTypePhotoLibrary; break; } } else{ if (buttonIndex==0) { return; }else { sourceType= UIImagePickerControllerSourceTypeSavedPhotosAlbum; }} // 跳转到相机或相册页面 UIImagePickerController *imagePickerController= [[UIImageP
6、ickerControlleralloc]init]; imagePickerController.delegate= self; imagePickerController.allowsEditing = YES; imagePickerController.sourceType=sourceType; [self presentViewController:imagePickerControlleranimated:YEScompletion:^{}]; }}#pragmamark -image picke
7、rdelegte- (void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info{ﻩ[pickerdismissViewControllerAnimated:YEScompletion:^{}]; UIImage*image=[infoUIImagePickerControllerOriginalImage]; userImageView。image=ima
8、ge; NSData *imageData=UIImageJPEGRepresentation(image, COMPRESSED_RATE);UIImage *compressedImage=[UIImageimageWithData:imageData]; [HttpRequestManageruploadImag
此文档下载收益归作者所有