相关资料http://blog.sina.com.cn/s/blog_a843a8850101flo3.html
http://blog.csdn.net/enuola/article/details/8076221
http://carlme.blog.163.com/blog/static/1837163272012715173659/
A data object containing the JPEG data, or nil if there was a problem generating the data. This function may return nil if the image has no data or if the underlying CGImageRef contains data in an unsupported bitmap format.
UIKIT_EXTERN NSData * __nullable UIImagePNGRepresentation(UIImage * __nonnull image); // return image as PNG. May return nil if image has no CGImageRef or invalid bitmap format
UIKIT_EXTERN NSData * __nullable UIImageJPEGRepresentation(UIImage * __nonnull image, CGFloat compressionQuality); // return image as JPEG. May return nil if image has no CGImageRef or invalid bitmap format. compression is 0(most)..1(least)
项目中自定义的用来保存UIImage
+(void)saveImageToDomainsWithDirectorystringByAppendingPathComponent:(NSString *)suffix WithImage:(UIImage *)image{
//JEPG格式
//压缩图片
NSData *imagedata=UIImageJPEGRepresentation(image,1.0);
//获取沙盒路径
NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
//获取documents路径
NSString *documentsDirectory=[paths objectAtIndex:0];
//添加文件名及后缀
NSString *savedImagePath=[documentsDirectory stringByAppendingPathComponent:suffix];
//写入文件
[imagedata writeToFile:savedImagePath atomically:YES];
}
//取图片
+ (UIImage *)fetchImageWithDirectorystringByAppendingPathComponent:(NSString *)suffix{
NSString *aPath3=[NSString stringWithFormat:@"%@/Documents/%@.png",NSHomeDirectory(),suffix];
UIImage *imgFromUrl3=[[UIImage alloc]initWithContentsOfFile:aPath3];
UIImageView* imageView3=[[UIImageView alloc]initWithImage:imgFromUrl3];
return imageView3.image;
}