iOS _ 图片保存到本地相册
2016-04-07 18:04
405 查看
#import "ViewController.h" #import "UIImageView+WebCache.h" @interface ViewController () @property (nonatomic, strong) UIImageView *imageV; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self addSubVIews]; } - (void)addSubVIews { self.imageV = [[UIImageView alloc] initWithFrame:(CGRectMake(100, 100, 200, 100))]; [self.imageV sd_setImageWithURL:[NSURL URLWithString:@"http://ac-YML68WwP.clouddn.com/T1kBOXK1jcegpCbxPnlvEeA.jpg"]]; [self.view addSubview:self.imageV]; UIButton *button=[[UIButton alloc]init]; button.frame= CGRectMake(100,300, 100,40); [button addTarget:self action:@selector(actionClick:)forControlEvents:UIControlEventTouchUpInside]; [button setTitleColor:[UIColor blueColor]forState:UIControlStateNormal]; [button setBackgroundColor:[UIColor orangeColor]]; [button setTitle:@"保存图片"forState:UIControlStateNormal]; [self.view addSubview:button]; } -(void)actionClick:(UIButton*)button { UIImageWriteToSavedPhotosAlbum(self.imageV.image,self,@selector(image:didFinishSavingWithError:contextInfo:),NULL); } //指定回调方法 -(void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo { if(!error){ NSLog(@"保存成功"); }else{ NSLog(@"保存失败"); } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
注: 首次运行此程序会提示访问相册
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 按右键另存图片只能存BMP
- photoshop去除图片上的水印
- upload上传单张图片
- 图片引发的溢出危机(图)
- C#实现把彩色图片灰度化代码分享
- C#将图片和字节流互相转换并显示到页面上
- C#监控文件夹并自动给图片文件打水印的方法
- 纯CSS实现的当鼠标移上图片添加阴影效果代码
- 如何使用C#从word文档中提取图片
- C#实现打开画图的同时载入图片、最大化显示画图窗体的方法
- C#图片添加水印的实现代码
- 随鼠标移动的图片或文字特效代码
- CSS 图片横向排列实现代码