我通过这段代码将图像存储在本地...
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/