将图片写入相册
2015-10-27 11:20
225 查看
//图片在桌面上,获取原图片 for (int i = 0; i<9; i++) { NSString *file = [NSString stringWithFormat:@"/Users/aplle/Desktop/images/%d.jpg", i]; UIImage *image = [UIImage imageWithContentsOfFile:file]; //写入相册 UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); }
UIImageView*imageVc = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.jpg"]]; imageVc.frame = CGRectMake(100, 100, 100, 100); imageView = imageVc; [self.view addSubview:imageView]; UIButton*saveBtn = [UIButton buttonWithType:UIButtonTypeContactAdd]; saveBtn.frame = CGRectMake(10, 10, 20, 20); [saveBtn addTarget:self action:@selector(didClickCollectionButtonAction:) forControlEvents:UIControlEventTouchDown]; [self.view addSubview:saveBtn];
//存储相册到本地 - (void)didClickCollectionButtonAction:(UIButton *)button{ //直接存入本地相册可以用: UIImageWriteToSavedPhotosAlbum(imageView.image,nil,nil, nil); //需要回调方法或者检验是否存入成功: UIImageWriteToSavedPhotosAlbum(imageView.image,self,@selector(image:didFinishSavingWithError:contextInfo:),nil); } //检查是否存储成功 - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { // if (!error) NSLog(@"保存成功"); // else NSLog(@"保存失败"); if (error !=NULL) { UIAlertView *photoSave = [[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:@"%@",error]delegate:nil cancelButtonTitle:nil otherButtonTitles:nil ]; [photoSave show]; [photoSave dismissWithClickedButtonIndex:0 animated:YES]; photoSave =nil; }else { UIAlertView *photoSave = [[UIAlertView alloc]initWithTitle:@"\n\n保存成功" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; [photoSave show]; [photoSave dismissWithClickedButtonIndex:0 animated:YES]; photoSave =nil; } }
相关文章推荐
- android stadio点滴1
- 那些不让客户察觉到但可以把oracle拖慢的参数
- .NET MVC4 用HttpClient后台post 请求webapi
- [转]推荐一个简单、轻量、功能非常强大的C#/ASP.NET定时任务执行管理器组件–FluentScheduler
- md5
- C# 通过GPS坐标,计算两点之间距离
- 传统的项目经理可以担当Scrum Master吗
- wincc c脚本 密码找回
- iOS8 Share Extension
- Log4j.properties配置详解
- Apache的用户认证及域名跳转
- java 数组与集合(list)相互转化
- 代码性能优化策略
- 单置换检验,轮廓检验及其他程序
- 新bolg地址 http://www.milletblog.com/
- iOS心得7 按钮的图片和文字自定义位置
- Android Studio 使用 Gradle 打包 Jar
- 孔浩Maven视频教程
- Activity的四种launchMode
- 美团大众点评合并:背后技术力量的对比回顾