ios - 加载以前从相机胶卷中保存的图像

标签 ios objective-c iphone uiimageview

所以我从相机胶卷或相机中保存了一张图像,并保存了目录和图像名称以供引用。当我回到我希望该图像显示的位置时,它不会。这只是一个空白 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/

相关文章:

iphone - 在 Objective-C 中对数组进行排序

iphone - App Store 中的 iPhone 应用程序真的可以接受 Flash 5.5 和 Flex 4.5 吗?

ios - 快捷方式项目,快速操作 3D Touch swift

ios - 如何使用 Swift 4.2 设置标志并将一些值从 Popup present modal viewcontroller 传递到 Tabbar Mein Viewcontroller?

c++ - 在 Objective-C++ 中重载 [] 运算符

ios - ScrollView 中的分段控件

ios - Swift,如何在 AVPlayer 上播放视频时获得事件点击完成按钮?

iphone - 从网页中读取字符串

ios - 未经许可或询问访问 iOS 联系人列表 - 隐私问题

ios - ADAL 身份验证需要设备管理