3

Intention: creating CGLayer offscreen, draw some complicated stuff on it from second thread and use it later for quick drawing on main thread

Problem: CGLayerCreateWithContext(context, size, info) expects an already existing CGContext so that it knows for what kind of context it needs to be optimized.

Solution I found so far: CGContextRef ctx = UIGraphicSetCurrentContext() but this function doesn't seem to exist anymore.

Question: Isn't there another way to access something like a default context? Or do i really need to wait for the first drawRect: call just for accessing UIGraphicsGetCurrentContext() and creating all CGLayers from main thread with one wasted drawing run?

weezor
  • 2,621
  • 1
  • 16
  • 10

1 Answers1

1

you can create an image context by doing something like:

UIGraphicsBeginImageContext(rect);
    // your drawing code
UIGraphicsEndImageContext();

with that said, i'm not sure you can do this from a thread other than main. worth a try, though.

Mike K
  • 2,227
  • 1
  • 12
  • 6
  • 1
    that's what I'm currently using. works fine. but the docs says "CGLayer object is a much better representation than a bitmap context" and also that it can be used in much the same way. but how? – weezor Dec 27 '11 at 01:57