总会遇到一些应用 要拍照 设置图片之类的的  总结一个方法备用  以后 会 继续拓展到 多图

@interface AddCustomerViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
UIImage *chosenImage;//做显示在self.view 上的image
NSString *tempImagePath;//图片路径
UIButton *button_Photo;//点击从系统选图片
}
@end
//以上代理 和参数 都是必须有的

-(void)TakePhoto
{
UIActionSheet *actionSheet =[[UIActionSheet alloc]initWithTitle:@"您想如何获取照片?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", nil];
[actionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
/*
NSLog(@"%ld",(long)buttonIndex);//2--->取消
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
if(buttonIndex==0)
{//拍照
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
}
else if(buttonIndex==1)
{//图库
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentViewController:picker animated:YES completion:NULL];
*/
NSLog(@"%ld",(long)buttonIndex);//2--->取消 if(buttonIndex==)
{//拍照
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
} } #pragma -mark UIImagePickerController delegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
chosenImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
//删除缓存文件
if ([[NSFileManager defaultManager] fileExistsAtPath:tempImagePath]) {
NSLog(@"the image is exist");
NSFileManager *defaultManager; defaultManager = [NSFileManager defaultManager];
NSError *error = [[NSError alloc] init];
[defaultManager removeItemAtPath:tempImagePath error:&error]; }
[UIImagePNGRepresentation(chosenImage) writeToFile:[ NSTemporaryDirectory() stringByAppendingPathComponent:@"temp_image.png"] atomically:YES]; BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:tempImagePath]; if (fileExists) {
NSLog(@"success");
customer_Inform.image_Head=chosenImage;
[button_Photo setImage:chosenImage forState:UIControlStateNormal]; }
[picker dismissViewControllerAnimated:YES completion:NULL]; if (fileExists) {
NSLog(@"success");
[SGInfoAlert showInfo:@" 照片添加成功! "
bgColor:[[UIColor darkGrayColor] CGColor]
inView:self.view
vertical:0.5];
}
else
{
[SGInfoAlert showInfo:@" 照片添加不成功! "
bgColor:[[UIColor darkGrayColor] CGColor]
inView:self.view
vertical:0.5];
}
// //也能用
// [button_Photo setImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"] forState:UIControlStateNormal];
// [picker dismissViewControllerAnimated:YES completion:NULL];
}

 

IOS 从系统图库中获取 图片 并设置为头像的更多相关文章

  1. Android 如何从系统图库中选择图片

    转:http://blog.csdn.net/tody_guo/article/details/7560270 这几天我都在做Android的App,同时学习它的API,我将分享一些我学到的东西,比如 ...

  2. ios 从url字符串中获取图片名字

    NSString *str = @"http://pic92.nipic.com/file/20160323/22486259_160209631000_2.jpg"; NSLog ...

  3. iOS中获取系统相册中的图片

    一.获取单张图片 思路: 1.利用UIImagePickerController可以从系统自带的App(照片\相机)中获得图片 2.设置代理,遵守代理协议 注意这个UIImagePickerContr ...

  4. ios从相册:摄像头中获取视频

    ios从相册/摄像头中获取视频 如何从相册中获取视频 使用的是一个和获取照片相同的类UIImagePickerController //相册中获取视频 - (IBAction)clickViedoOF ...

  5. android 调用系统照相机拍照后保存到系统相册,在系统图库中能看到

    需求:  调用系统照相机进行拍照,并且保存到系统相册,调用系统相册的时候能看到   系统相册的路径:String cameraPath= Environment.getExternalStorageD ...

  6. iOS--app自定义相册--从自定义的相册中获取图片

    一.获取单张图片 思路: 1.利用UIImagePickerController可以从系统自带的App(照片\相机)中获得图片 2.设置代理,遵守代理协议 注意这个UIImagePickerContr ...

  7. iOS学习笔记31-从图册获取图片和视频

    一.从图册中获取本地图片和视频 从图册中获取文件,我们使用的是UIImagePickerController,这个类我们在之前的摄像头中使用过,这里是链接:iOS学习笔记27-摄像头,这里我们使用的是 ...

  8. Android向系统相册中插入图片,相册中会出现两张 一样的图片(只是图片大小不一致)

    向系统相册中插入图片调用此方法时,相册中会出现两张一样的图片 MediaStore.Images.Media.insertImage 一张图片是原图一张图片是缩略图.表现形式为:android4.4. ...

  9. java如何从一段html代码中获取图片的src路径

    java如何从一段html代码中获取图片的src路径 package com.cellstrain.icell.Test; import java.util.ArrayList;import java ...

随机推荐

  1. Spring.Scheduling.Quartz的使用

    最近因使用Spring.Net框架而接触.了解到其与Quartz.Net的集成,即Spring.Scheduling.Quartz模块. Spring通过对Quartz.Net的封装,采用了sprin ...

  2. POJ3253Fence Repair(优先队列或单调队列)

    http://poj.org/problem?id=3253 经典题目了,大意是说如果要切断一个长度为a的木条需要花费代价a, 问要切出要求的n个木条所需的最小代价. 无论是以下哪种方法,最原始的思路 ...

  3. Unity中的C#规则

    命名 文件名和Class要一致(CamelCase) 类公共和保护类型Property(CamelCase) 类的公共和保护类型Fields(CamelCase)* 先采用.Net的命名方法,如果出现 ...

  4. Find mac address

    Windows Method 1: Using the Command Prompt 1 Click on the Start button.   2 Type cmd in the search b ...

  5. Gson 和 Fastjson 你不知道的事

    背景 目前在公司负责的业务, 主要是跟JSON数据打交道, fastjson .gson都用, 他们适用于不同场景.fastjson号称是业界处理json效率最高的框架, 没有之一.但在某些场景下, ...

  6. 去除移动端 a标签 点击有一个 阴影效果

    outline: none;appearance:none;  -webkit-tap-highlight-color: transparent;   

  7. head first-----------adpter pattern

    head first-----------------深入浅出适配器模式      适配器模式:将一个类的接口,转换成客户想要的另外一个接口,适配器然原本接口不兼容的类可以合作无间.从而可以不用更改旧 ...

  8. T4模板语法

    T4,即4个T开头的英文字母组合:Text Template Transformation Toolkit. T4文本模板,即一种自定义规则的代码生成器.根据业务模型可生成任何形式的文本文件或供程序调 ...

  9. STM32 DFU -- Device Firmware Upgrade

    DFU Class Requests Get Status The Host employs the DFU_GETSTATUS request to facilitate synchronizati ...

  10. C++学习笔记之友元

    一.引言 C++控制对类对象私有部分(private)的访问,通常只能通过公有的(public)类方法去访问.但是有时候这种限制太严格,不适合特定的问题,于是C++提供了另外一种形式的访问权限:友元. ...