I just need to know hot to create a CGLayer
that has an image drawn to it. I am not completely understanding the documentation entirely. Thanks
Asked
Active
Viewed 1,316 times
0

Jab
- 26,853
- 21
- 75
- 114
-
For basic info on CGlayer, this may well help ... http://stackoverflow.com/questions/4458812/whats-the-difference-and-compatibility-of-cglayer-and-calayer/4594394#4594394 – Fattie Apr 17 '12 at 14:09
1 Answers
0
A while ago I posted a blog post on a similar topic, available here:
Drawing UIImages right side up using CoreGraphics
In that post, I show how to draw a UIImage so that's it's grayscale. Part of that includes creating a new layer with a gray colorspace (so it draws in shades of gray), and then extracting the CGContextRef
from the CGLayer
, pushing it to the context stack, drawing the UIImage
, and then popping the context stack. The UIImage
draws onto the topmost CGContextRef
, which will be the context that corresponds to your CGLayer
.
There are probably other ways to do this, but this is how I've done it in the past, and it's always worked great for me.

Dave DeLong
- 242,470
- 58
- 448
- 498
-
When changing the .image property of an UIImageView, do you know if the system is using CGLayer to get good performance ? Or do I need to use your code to get a better FPS ? – CedricSoubrie Aug 22 '11 at 09:26
-
1@Cedric it's getting passed through to the underlying `CALayer`, so it's not going through a `CGLayer` at all. – Dave DeLong Aug 22 '11 at 13:27