如何使用NSFileManager将UIImage保存到文件? [英] How to save UIImage to file with NSFileManager?

查看:184
本文介绍了如何使用NSFileManager将UIImage保存到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用NSFileManager将UIImage保存到文件?

How I can save UIImage to file with NSFileManager ?

谢谢

推荐答案

在这里.

这会将UIImage存储到iOS应用的文档目录中. 您不需要NSFileManager.

This will store a UIImage into your documents directory of your iOS App. You won't need NSFileManager.

NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

UIImage * imageToSave = [UIImage imageNamed:@"Icon.png"];
NSData * binaryImageData = UIImagePNGRepresentation(imageToSave);

[binaryImageData writeToFile:[basePath stringByAppendingPathComponent:@"myfile.png"] atomically:YES];

修改: 如果您是通过iOS相机存储图像的,则可以查看如何将图像旋转到正确的方向. 在这种情况下,请查看此处.

If you store images form the iOS Camera, you might look at how you can rotate the images to the right orientation. Look here in that case.

这篇关于如何使用NSFileManager将UIImage保存到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆