Re: Best way to draw NSBezierPath to CIImage
Re: Best way to draw NSBezierPath to CIImage
- Subject: Re: Best way to draw NSBezierPath to CIImage
- From: Darkshadow <email@hidden>
- Date: Sat, 21 Jul 2007 18:21:41 -0400
On Jul 21, 2007, at 10:26 AM, Nik Youdale wrote:
Hey there,
What is the best way to draw an NSBezierPath (or anything else from
cocoa drawing - will settle for core graphics if necessary) to a
CIImage?
I have tried making a CGLayer and with a NSBitmapImageRep based
context, and then drawing to that.. creating a CIImage from that
and compositing that on top of my target CIImage via one of the
compositing CIFilters...
This all seems a bit longwinded, and is very very slow. The
bezierpath changes shape a lot too.
Any help would be very much appreciated
Cheers
Nik
I think that's pretty much the way you'll need to do it, since you
can't draw to a CIImage directly. You can, though, draw directly to
the CGLayer. That may speed up things a small bit.
Something like this (typed in Mail, not tested):
----------------------------
//If you're only using this from within -drawRect:, you can use
[NSGraphicsContext currentContext] on the next line instead
NSGraphicsContext *currentContext = [myWindow graphicsContext];
NSGraphicsContext *pathContext = nil;
if ( pathLayer == NULL ) {
pathLayer = CGLayerCreateWithContext( [currentContext graphicsPort],
layerSize, NULL );
}
pathContext = [NSGraphicsContext
graphicsContextWithGraphicsPort:CGLayerGetContext( pathLayer )
flipped:isFlipped];
[NSGraphicsContext setCurrentContext:pathContext];
//Draw your bezier paths here
[NSGraphicsContext setCurrentContext:currentContext];
myCIImage = [CIImage imageWithCGLayer:pathLayer];
-----------------------------
You take a (very small) hit by setting the graphics context, but it's
most likely quicker than creating a NSBitmapImageRep and drawing to
that. You can also reuse the CGLayerRef so long as you remember to
clear out the previous drawing (just setting a clear color and then
using that to fill will work). That will save you a bit over having
to create the CGLayerRef every time you want to draw your paths.
--------------------------------------
Darkshadow
(aka Michael Nickerson)
http://www.nightproductions.net
_______________________________________________
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