从文档目录EasyAR加载图像

时间:2019-10-06 10:48:21

标签: ios swift easyar

我想动态加载图像。因此,从服务器获取图像后,我将其保存在Documents Directory中。如何在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)
    }
}

0 个答案:

没有答案