1.保存到iOS照片库需要引入QuartzCore.framework框架,具体代码如下:
.h文件
#import <QuartzCore/QuartzCore.h>
UIImageView *imageView;
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
.m文件
UIGraphicsBeginImageCont ext(imageView.bounds.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentCont ext()];
UIImage *temp = UIGraphicsGetImageFromCu rrentImageContext();
UIGraphicsEndImageContex t();
UIImageWriteToSavedPhoto sAlbum(temp,
nil, nil, nil);
2.保存到对应的沙盒目录中,具体代码如下:
NSArray *paths = NSSearchPathForDirectori esInDomains(NSDocumentDirectory,NSUserDomainMask,
YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathCom ponent:[NSString
stringWithFormat:@"sms.gif"]]; //
保存文件的名称
BOOL result = [UIImagePNGRepresentation (imageView.image)writeToFile:
filePath atomically:YES];
// 保存成功会返回YES
.h文件
#import <QuartzCore/QuartzCore.h>
UIImageView *imageView;
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
.m文件
UIGraphicsBeginImageCont
[imageView.layer renderInContext:UIGraphicsGetCurrentCont
UIImage *temp = UIGraphicsGetImageFromCu
UIGraphicsEndImageContex
UIImageWriteToSavedPhoto
2.保存到对应的沙盒目录中,具体代码如下:
NSArray *paths = NSSearchPathForDirectori
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathCom
BOOL result = [UIImagePNGRepresentation
本文介绍了两种在iOS应用中保存图片的方法:一种是将图片保存到iOS的照片库中,使用QuartzCore.framework框架实现;另一种是将图片保存到应用程序的沙盒目录中。
1950

被折叠的 条评论
为什么被折叠?



