How to Load Lcr Image in Tvos Apps

Unable to load LCR image in tvOS apps

Ok I kind of found the work around myself for this problem. So I am posting here if in case anyone else is facing same problem. Below is code with explanation:

if let url = NSURL(string: "https://.lcr-file-url") {
if let data = NSData(contentsOfURL: url){
let documents = NSURL(string: NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)[0])
let writePath = documents!.URLByAppendingPathComponent("file.lcr")
data.writeToFile(writePath.absoluteString, atomically: true)
let image = UIImage(contentsOfFile: writePath.absoluteString)
}
}

Basically we need to download the image data and save it in some local file and use contentsOfFile method to have actual image.

If anyone else know better solution than this, I would be happy to hear :)

Creating a UIImage from a remote LSR file

That's how i solved it:

  1. Convert you .lsr file to a .lcr file doing this from console:
    xcrun --sdk appletvos layerutil --c your_file.lsr
  2. Upload your_file.lcr on your server
  3. Put these two functions into an util class:

    func getDataFromUrl(url:NSURL, completion: ((data: NSData?, response: NSURLResponse?, error: NSError? ) -> Void)) {
    NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) in
    completion(data: data, response: response, error: error)
    }.resume()
    }

    func downloadImage(url: NSURL, imageView: UIImageView){
    print("Started downloading \"\(url.URLByDeletingPathExtension!.lastPathComponent!)\".")
    getDataFromUrl(url) { (data, response, error) in
    dispatch_async(dispatch_get_main_queue()) { () -> Void in
    guard let data = data where error == nil else { return }
    print("Finished downloading \"\(url.URLByDeletingPathExtension!.lastPathComponent!)\".")
    imageView.image = UIImage(data: data)
    }
    }
    }
  4. Use it like this:

    if let checkedUrl = NSURL(string: "http://domain/path/to/your_file.lcr") {
    self.my_ui_view.contentMode = .ScaleAspectFit
    downloadImage(checkedUrl, imageView: self.my_ui_view.contentMode)
    }

This will use the image without saving it into the document directory, if you need that solution, ask me and i'll share.

How to create a tvOS icon without Photoshop

You don't need to deal with .lsr file at all. You just need to have separate PNG file for each layer, and construct the "App Icon - Small" with them in the asset file. Xcode even gives you a nice Parallax preview.

Therefore, you don't need to use PhotoShop at all. Any app that can deal with PNG files (even the Preview app of OSX) is sufficient.



Related Topics



Leave a reply



Submit