iphone - 我们如何从本地获取图像?

标签 iphone ios

我通过这段代码将图像存储在本地...

NSData *imageData = UIImagePNGRepresentation(image);
NSString *imageName = [NSString stringWithFormat:@"image.png"];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];

[imageData writeToFile:fullPathToFile atomically:YES];

我可以在我的 iphone 模拟器包中看到这张图片......但是我怎样才能取回这张图片?

最佳答案

如果您的意思是从文件重新创建图像,您可以使用 UIImage+imageWithContentsOfFile: 非常简单地做到这一点。方法:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"someImageName"];
UIImage *image = [UIImage imageWithContentsOfFile:fullPathToFile];

关于iphone - 我们如何从本地获取图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4766533/

相关文章:

iphone - iOS 5 上 NSDictionary 中出现奇怪的重复键,而 iOS 6 上则不然

ios - 如何检查应用程序特定的 CloudKit 数据,或访问 iTunes 应用程序中无法访问的数据?

iphone - 刷新 UITabBar 选项卡的 View 或在重新选择选项卡时从 UITabBar 选项卡的 View 调用方法

iphone - RootViewController 动画过渡,初始方向错误

c# - MonoTouch - 来自 Pointer 的 CGImage 使应用程序崩溃 - iPhone

iphone - 视频 Airplay 支持 webapp

iPhone 当前时区与 UTC 的偏移

iphone - UITableView 滚动缓慢

ios - 在SCNView上启用用户交互后,如何让它只水平旋转?

ios - UIButton反转并发问题