Re: setting a CGContextRef to the current Context
Re: setting a CGContextRef to the current Context
- Subject: Re: setting a CGContextRef to the current Context
- From: Scott Thompson <email@hidden>
- Date: Wed, 08 Jul 2009 18:20:22 -0500
On Jul 8, 2009, at 6:03 PM, David Alter wrote:
I have CGContextRef that I use for some quartz calls. It is a bitmap
context. I would like to set it as the current context so that I can
use
NSString drawAtPoint: withAttributes:. I do not see how to do this.
NSGraphicContext setCurrentContext: takes a NSGraphicContext and not
an
CGContextRef. I do not see a way to create a NSGraphicContext with a
CGContextRef. Nor do I see anything in the C API. So I'm a little
unclear
how I can set my bitmap Context to the current context so I can draw
my
string. Anyone have any ideas.
thanks for the help.
In the world of NSGraphicsContext, a CGContextRef is known as a
"graphicsPort".
So the routine you are looking for is:
+ (NSGraphicsContext *)graphicsContextWithGraphicsPort:(void *)
graphicsPort flipped:(BOOL)initialFlippedState;
You should typecast your CGContext to (void *) and pass it as the
graphicsPort argument.
Ater doing that you can use setCurrentContext. The whole thing looks
something like this
[NSGraphicsContext saveGraphicsState];
[[NSGraphicsContext graphicsContextWithGraphicsPort: (void *)
yourCGContextHere flipped: isFlipped] setCurrentContext];
... draw here...
[NSGraphicsContext restoreGraphicsState];
"Flipped" refers to the location of your origin and the orientation of
your coordinate system. Set flipped to YES if you've moved the origin
to the top left of the context and are using a left handed coordinate
system (x axis to the right, y axis pointing down).
You are likely going to want the flipped coordinate system to draw text.
Scott
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden