码迷,mamicode.com
首页 > 其他好文 > 详细

把UIImage保存到照片库和沙盒中

时间:2016-10-23 07:44:43      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:begin   arc   nonatomic   art   pen   port   照片   uiimage   call   

1、保存到iOS照片库需要引入QuartzCore.framework框架,具体代码如下:

.h文件

#import <QuartzCore/QuartzCore.h>
UIImageView *imageView;
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
.m文件
UIGraphicsBeginImageContext(imageView.bounds.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *temp = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(temp, nil, nil, nil);

2、保存到对应的沙盒目录中,具体代码如下:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"sms.gif"]];   // 保存文件的名称
BOOL result = [UIImagePNGRepresentation(imageView.image)writeToFile: filePath atomically:YES]; // 保存成功会返回YES 

 

把UIImage保存到照片库和沙盒中

标签:begin   arc   nonatomic   art   pen   port   照片   uiimage   call   

原文地址:http://www.cnblogs.com/pengyunjing/p/5988955.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!