UIImagePickerController的编辑模式怎么设置裁剪框的大小或形状
2个回答
2016-07-03
展开全部
UIImagePickerController是系统提供的用来获取图片和视频的接口;用UIImagePickerController类来获取图片视频,大体分为以下几个步骤:1.初始化UIImagePickerController类;2.设置UIImagePickerController实例的数据来源类型(下面解释);3.设置设置代理;4.如果需要做图片修改的话设置allowsEditing=yes。数据来源类型一共有三种:enum{UIImagePickerControllerSourceTypePhotoLibrary,//来自图库UIImagePickerControllerSourceTypeCamera,//来自相机UIImagePickerControllerSourceTypeSavedPhotosAlbum//来自相册};在用这些来源的时候最好检测以下设备是否支持;if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){NSLog(@"支持相机");}if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){NSLog(@"支持图库");}if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]){NSLog(@"支持相片库");}调用摄像头来获取资源-(void)viewDidLoad{[superviewDidLoad];picker=[[UIImagePickerControlleralloc]init];picker.view.backgroundColor=[UIColororangeColor];UIImagePickerControllerSourceTypesourcheType=UIImagePickerControllerSourceTypeCamera;picker.sourceType=sourcheType;picker.delegate=self;picker.allowsEditing=YES;}上面只是实例了UIImagePickerController及其属性在需要获取图片的时候需要弹出窗口调用[selfpresentViewController:pickeranimated:YEScompletion:nil];我们还需要代理来获取我们选中的图片UIImagePickerControllerDelegate代理中一共三个方法其中一个3.0已经废弃了,只剩下两个我们需要用的-(void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary*)info;当用户选取完成后调用;-(void)imagePickerControllerDidCancel:(UIImagePickerController*)picker;当用户取消选取时调用;-(void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary*)info;选取的信息都在info中,info是一个字典。字典中的键:NSString*constUIImagePickerControllerMediaType;指定用户选择的媒体类型(文章最后进行扩展)NSString*constUIImagePickerControllerOriginalImage;原始图片NSString*constUIImagePickerControllerEditedImage;修改后的图片NSString*constUIImagePickerControllerCropRect;裁剪尺寸NSString*constUIImagePickerControllerMediaURL;媒体的URLNSString*constUIImagePickerControllerReferenceURL;原件的URLNSString*constUIImagePickerControllerMediaMetadata;当来数据来源是照相机的时候这个值才有效UIImagePickerController的参数参考这里。代理中的功能参考这里。UIImagePickerControllerMediaType包含着KUTTypeImage和KUTTypeMovieKUTTypeImage包含:constCFStringRefkUTTypeImage;抽象的图片类型constCFStringRefkUTTypeJPEG;constCFStringRefkUTTypeJPEG2000;constCFStringRefkUTTypeTIFF;constCFStringRefkUTTypePICT;constCFStringRefkUTTypeGIF;constCFStringRefkUTTypePNG;constCFStringRefkUTTypeQuickTimeImage;constCFStringRefkUTTypeAppleICNSconstCFStringRefkUTTypeBMP;constCFStringRefkUTTypeICO;KUTTypeMovie包含:constCFStringRefkUTTypeAudiovisualContent;抽象的声音视频constCFStringRefkUTTypeMovie;抽象的媒体格式(声音和视频)constCFStringRefkUTTypeVideo;只有视频没有声音constCFStringRefkUTTypeAudio;只有声音没有视频constCFStringRefkUTTypeQuickTimeMovie;constCFStringRefkUTTypeMPEG;constCFStringRefkUTTypeMPEG4;constCFStringRefkUTTypeMP3;constCFStringRefkUTTypeMPEG4Audio;constCFStringRefkUTTypeAppleProtectedMPEG4Audio;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询