IOS 从系统图库中获取 图片 并设置为头像
2014-04-15 18:52
330 查看
总会遇到一些应用要拍照设置图片之类的的总结一个方法备用以后会继续拓展到多图
@interfaceAddCustomerViewController:UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate> { UIImage*chosenImage;//做显示在self.view上的image NSString*tempImagePath;//图片路径 UIButton*button_Photo;//点击从系统选图片 } @end //以上代理和参数都是必须有的
-(void)TakePhoto { UIActionSheet*actionSheet=[[UIActionSheetalloc]initWithTitle:@"您想如何获取照片?"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"拍照",nil]; [actionSheetshowInView:self.view]; } -(void)actionSheet:(UIActionSheet*)actionSheetclickedButtonAtIndex:(NSInteger)buttonIndex { /* NSLog(@"%ld",(long)buttonIndex);//2--->取消 UIImagePickerController*picker=[[UIImagePickerControlleralloc]init]; picker.delegate=self; picker.allowsEditing=YES; if(buttonIndex==0) {//拍照 picker.sourceType=UIImagePickerControllerSourceTypeCamera; } elseif(buttonIndex==1) {//图库 picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary; } [selfpresentViewController:pickeranimated:YEScompletion:NULL]; */ NSLog(@"%ld",(long)buttonIndex);//2--->取消 if(buttonIndex==0) {//拍照 UIImagePickerController*picker=[[UIImagePickerControlleralloc]init]; picker.delegate=self; picker.allowsEditing=YES; picker.sourceType=UIImagePickerControllerSourceTypeCamera; [selfpresentViewController:pickeranimated:YEScompletion:NULL]; } } #pragma-markUIImagePickerControllerdelegate -(void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary*)info { chosenImage=[infoobjectForKey:@"UIImagePickerControllerOriginalImage"]; //删除缓存文件 if([[NSFileManagerdefaultManager]fileExistsAtPath:tempImagePath]){ NSLog(@"theimageisexist"); NSFileManager*defaultManager; defaultManager=[NSFileManagerdefaultManager]; NSError*error=[[NSErroralloc]init]; [defaultManagerremoveItemAtPath:tempImagePatherror:&error]; } [UIImagePNGRepresentation(chosenImage)writeToFile:[NSTemporaryDirectory()stringByAppendingPathComponent:@"temp_image.png"]atomically:YES]; BOOLfileExists=[[NSFileManagerdefaultManager]fileExistsAtPath:tempImagePath]; if(fileExists){ NSLog(@"success"); customer_Inform.image_Head=chosenImage; [button_PhotosetImage:chosenImageforState:UIControlStateNormal]; } [pickerdismissViewControllerAnimated:YEScompletion:NULL]; if(fileExists){ NSLog(@"success"); [SGInfoAlertshowInfo:@"照片添加成功!" bgColor:[[UIColordarkGrayColor]CGColor] inView:self.view vertical:0.5]; } else { [SGInfoAlertshowInfo:@"照片添加不成功!" bgColor:[[UIColordarkGrayColor]CGColor] inView:self.view vertical:0.5]; } ////也能用 //[button_PhotosetImage:[infoobjectForKey:@"UIImagePickerControllerOriginalImage"]forState:UIControlStateNormal]; //[pickerdismissViewControllerAnimated:YEScompletion:NULL]; }
相关文章推荐
- 获取系统图库的图片设置头像
- iOS开发swift如何调用系统相册和相机获取图片设置用户头像
- iOS 调用相机拍照和选择图库图片 设置头像
- iOS设置用户头像(从相册,图库或者拍照获取)
- android 相机拍照或从图库获取图片并裁剪设置头像
- iOS上传图片到网上,并更新到服务器,常用在设置头像
- android-调用系统的ContentPrivder获取单张图片实现剪切做头像及源代码下载
- android选择系统相机拍照和系统相册,裁剪图片并保存和设置头像,适配至7.0
- 头像的选择 从图库、照相机照片 设置 图片为头像
- 安卓实现调用系统图库与相机设置头像并保存在本地及服务器
- Android解决部分机型获取不到系统拍照图片,图库图片问题的解决
- 解决Android4.4及以上系统获取系统图片失败的问题,例如华为手机,调系统图库的时候就出现异常
- Qt for iOS:使用UIImagePickerController获取一个系统相册中的图片
- iOS开发 获取系统相册最后一张图片 、 截屏广播
- iOS 获取系统全部图片
- iOS图片处理(一)调用系统相机和相册获取图片,给相机添加自定义覆盖物
- Android 从本地图库或拍照后裁剪图片并设置头像
- iOS 获取系统wifi列表,wifi信号强度,并给wifi设置密码,标签(副标题)
- Android实现调用系统图库与相机设置头像并保存在本地及服务器
- 调用系统拍照和在系统图库选择照片设置头像