Load image without any compression from Assets.xcassets

In my project, I pack two normal maps into one large size (4096x4096) texture(R,G channel for one, and B,Alpha for another).

If I use [UIImage imageNamed:] to load the image from the asset bundle, no matter how I set the compression for the image(lossless or other options), the result UIImage always has artifacts in each color channel(each channel contains colors coming from other channel. Default lossless option is the best among others, but still not acceptable). Because I use the pixels for normal map animation, these artifacts are noticeable.

If I move the image from asset bundle to project folder, and load it by using [[UIImage alloc]initWithContentFile:], because of no compression, the artifact goes away. But I get no benefits from image caching.

So, is there any workaround to load the image without compression while can be cached?



There's surely a better answer that involves some configuration of the asset. But its strikes me that encoding your asset as a dataset would ensure that the asset compiler attempts to perform no optimizations on your image data.

Load image without any compression from Assets.xcassets
 
 
Q