ios - 从文档目录 EasyAR 加载图像
问题描述
我想动态加载图像。因此,从服务器获取图像后,我将其保存在文档目录中。如何在 ImageTarget 中加载该图像。
有没有其他方法来处理这个?
这就是我将图像存储在文档目录中的方式。如果需要,我可以更改存储逻辑作为我的主要目的,如果从服务器获取图像然后在该图像上显示 AR。我不想为此使用 EasyAR 的可能识别。
// get the documents directory url
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
// choose a name for your image
let fileName = "image.jpg"
// create the destination file url to save your image
let fileURL = documentsDirectory.appendingPathComponent(fileName)
// get your UIImage jpeg data representation and check if the destination file url already exists
if let data = image.jpegData(compressionQuality: 1.0),
!FileManager.default.fileExists(atPath: fileURL.path) {
do {
// writes the image data to disk
try data.write(to: fileURL)
print("file saved")
} catch {
print("error saving file:", error)
}
}
解决方案
推荐阅读
- .net - 在 Linux 上安装特定版本的 .NET Core 运行时
- python-3.x - 如何使用 numpy 获取矩阵的小数
- reactjs - 材质 ui InputLabel 组件的样式更改不起作用。下面的代码
- python - 为什么 Python 的 map 函数和 for 循环之间没有速度差异?
- javascript - vuejs 数据更新,但更改未反映在模板中
- data-structures - 访问数据结构是什么意思
- javascript - MongoDB 找不到刚刚创建的文档
- javascript - 有没有办法证明这一点?
- r - R - 选择案例,以便变量的平均值是某个给定的数字
- html - 元素间隙的弹性盒空间均匀选择器?