I am wondering what the most efficient way is to make a CALayer with an image in it.
I know you can load a UIImage and then call [image CGImage] but is this the best way of going about it? As far as I can tell from Apple’s documentation this is the only way you can do it.
Well, a
CGImageisn’t aCALayer, so you are obviously leaving some steps out there, but I assume you know what you’re talking about, as far as drawing to aCALayeror whatnot.If your question is about creating
CGImages without using a UIImage, you can try looking into the following functions:If you happen to know beforehand what sort of image it is, just use the appropriate method. Otherwise, you’d need to look at the file signature to see if it contains PNG or JFIF. Of course, this requires you implement a
CGDataProvider.I assume this is exactly what the
UIImageclass is already doing. If you want to squeeze out every bit of efficiency from that, you can use one of the following methods in theUIImageclass:The only difference between these methods and
is that
imageNamed:caches the image. If you use one of the first methods, it does not.