Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path Parameter in UIImage imageWithContentsOfFile: for XCAsset

Is there any way to retrieve a UIImage object with imageWithContentsOfFile: if the image is stored in an xcasset Bundle (Xcode 5 Image Catalog)?

It's easy to access it with the imageNamed: method, but imageWithContentsOfFile: has a slightly different behavior, so what do I pass in the path parameter?

I've tried to use a variety of formats, but they all return a nil value:

Apple's documentation doesn't specify a format for this. Any ideas?

like image 333
Sam Spencer Avatar asked Dec 15 '13 22:12

Sam Spencer


1 Answers

You can't load an image from xcasset via imageWithContentsOfFile:, because every entry in xcasset is compiled into a single binary file Assets.car. The format of this file is not documented and yet not reverse-engeneered well afaik (see "What you should know if you want to try reverse-engineering this stuff." section for explanations).

This is done for performance and low memory consume reasons, that's why imageNamed: is a good solution.

like image 172
Sega-Zero Avatar answered Oct 21 '22 17:10

Sega-Zero