相关资料
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 formatUIKIT_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;}