1.保存到iOS照片庫(kù)需要引入QuartzCore.framework框架央星,具體代碼如下:
.h文件
#import
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.保存到對(duì)應(yīng)的沙盒目錄中蕊玷,具體代碼如下:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"sms.gif"]];// 保存文件的名稱
BOOL result = [UIImagePNGRepresentation(imageView.image)writeToFile: filePathatomically:YES]; // 保存成功會(huì)返回YES