UIImage保存为JPG,PNG的方法


View Code
 1 / Create paths to output images
2 NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
3 NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
4
5 // Write a UIImage to JPEG with minimum compression (best quality)
6 // The value 'image' must be a UIImage object
7 // The value '1.0' represents image compression quality as value from 0.0 to 1.0
8 [UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
9
10 // Write image to PNG
11 [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
12
13 // Let's check to see if files were successfully written...
14
15 // Create file manager
16 NSError *error;
17 NSFileManager *fileMgr = [NSFileManager defaultManager];
18
19 // Point to Document directory
20 NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
21
22 // Write out the contents of home directory to console
23 NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
优质内容筛选与推荐>>
1、Web2.0 (social media) 企业应用的架构
2、Mac实用操作技巧(七)
3、计算机网络(第七版) 第一章
4、Django-缓存、信号
5、【原创】闫若川FPGA轻松入门:开发环境搭建


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn