所以我从相机胶卷或相机中保存了一张图像,并保存了目录和图像名称以供引用。当我回到我希望该图像显示的位置时,它不会。这只是一个空白 ImageView 。
我觉得这应该是直截了当的,我已经做了自己的研究,但似乎没有答案对我有用。
下面是图像路径和我用来尝试显示图像的代码。我在这里做错了什么?
/Users/*****/Library/Developer/CoreSimulator/Devices/FA19C634-C029-4518-BAE1-E7CC601FB9C2/data/Containers/Data/Application/72B5C82B-A8FB-451D-A6DC-DF2C3F3ED12D/Documents/Profile Pics/CYKGXryEDj-1.jpg
self.imageView.image = [UIImage imageWithContentsOfFile:profileImg];
最佳答案
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"]; //Add the file name
NSData *pngData = [NSData dataWithContentsOfFile:filePath];
UIImage *image = [UIImage imageWithData:pngData];
关于ios - 加载以前从相机胶卷中保存的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30726062/