ios-上传头像并裁剪成正方形

微信扫一扫,分享到朋友圈

ios-上传头像并裁剪成正方形
-(void) selectWayToGetPicture{
UIActionSheet*actionSheet = [[UIActionSheetalloc]initWithTitle:nildelegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"拍照",@"图库",nilnil];
[actionSheetshowInView:self.view];
}
// 实现UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate
#pragma mark -actionSheetDelegate
-(void)actionSheet:(UIActionSheet*)actionSheetclickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex ==0) {
// 资源类型为照相机
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
// 判断是否有相机
if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController*picker = [[UIImagePickerControlleralloc]init];
picker.delegate=self;
picker.sourceType= sourceType;// 资源类型为照相机
picker.allowsEditing=YES;// 设置选择后的图片是否能被编辑
[selfpresentViewController:pickeranimated:YEScompletion:nil];
}else{
UIAlertView*alertView = [[UIAlertViewalloc]initWithTitle:nilmessage:@"该设备无摄像头"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:nilnil];
[alertViewshow];
}
}elseif(buttonIndex ==1){
UIImagePickerController*pickerController = [[UIImagePickerControlleralloc]init];
pickerController.sourceType= UIImagePickerControllerSourceTypePhotoLibrary;
pickerController.delegate=self;
pickerController.allowsEditing=YES;// 设置选择后的图片是否能被编辑
[selfpresentViewController:pickerControlleranimated:YEScompletion:nil];
}
}
-(void)imagePickerController:
(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary*)info {
NSString*type = [infoobjectForKey:UIImagePickerControllerMediaType];
// 当选择的类型是图片
if([typeisEqualToString:@"public.image"])
{
//需要改成UIImagePickerControllerEditedImage
UIImage* image = [infoobjectForKey:@"UIImagePickerControllerEditedImage"];// 裁剪后的图片
}
[pickerdismissViewControllerAnimated:YEScompletion:nil];
}

天猫618上线5折新车:大众、日产、比亚迪都有 最低3部iPhone钱

上一篇

乐信考虑合适时机在香港二次上市

下一篇

你也可能喜欢

ios-上传头像并裁剪成正方形

长按储存图像,分享给朋友