Nitesh
Nitesh

Reputation: 2034

Load Image from Documents Directory EasyAR

I want to load Image dynamically. So after fetching the image from Server, I'm saving it in Documents Directory. How to load that image in ImageTarget.

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

Storage Types: https://www.easyar.com/doc/EasyAR%20SDK/Unity%20Plugin%20Reference/2.0/StorageType.html?highlight=storagetype

Is there any other way to handle this?

This is how I'm storing the Image in documents directory. If required I can change the logic of storing as my main Purpose if to get the Image from Server and then show AR on that Image. I don't want to use EasyAR's Could Recognition for this.

// 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)
    }
}

Upvotes: 0

Views: 118

Answers (0)

Related Questions