首页 > 解决方案 > 从文档目录 EasyAR 加载图像

问题描述

我想动态加载图像。因此,从服务器获取图像后,我将其保存在文档目录中。如何在 ImageTarget 中加载该图像。

https://www.easyar.com/doc/EasyAR%20SDK/Unity%20Plugin%20Reference/1.0/ImageTarget.html?highlight=json

存储类型:https ://www.easyar.com/doc/EasyAR%20SDK/Unity%20Plugin%20Reference/2.0/StorageType.html?highlight=storagetype

有没有其他方法来处理这个?

这就是我将图像存储在文档目录中的方式。如果需要,我可以更改存储逻辑作为我的主要目的,如果从服务器获取图像然后在该图像上显示 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)
    }
}

标签: iosswifteasyar

解决方案


推荐阅读