NSBezierPath to NSImage with subpixel rendering
NSBezierPath to NSImage with subpixel rendering
- Subject: NSBezierPath to NSImage with subpixel rendering
- From: Gregory 'guardian' Pakosz <email@hidden>
- Date: Wed, 09 Jan 2008 12:40:38 +0100
Hello,
I am trying to stroke a bezier path into an off-screen buffer.
in the -initWithFrame: method of my custom view, i created an NSImage
instance
image = [[NSImage alloc] initWithSize:frameRect.size];
i created an NSBezierPath and added stuff:
path = [[NSBezierPath alloc] init];
[path *drawStuff*]; // drawing here
then, still inside -initWithFrame: i stroke the path into the image:
[image lockFocus];
[[NScolor whiteColor] set];
[NSBezierPath fillRect:[frameRect]];
[[NScolor blackColor] set];
[path stroke];
[image unlockFocus];
so by now, as part of my custom view initialization the NSImage instance
is supposed to contain my stroked path.
afterwards, in -drawRect: i just do:
[image drawInRect: rect
fromRect: rect
operation: NSCompositeCopy
fraction: 1.0];
by doing that, i don't benefit from subpixel precision :(
the problem is that it seems that subpixel rendering wasn't applied when
rendering into the NSImage, although i painted a white background (by
filling a white rect).
however, if i move the path stroking code into drawRect:
- (void)drawRect:(NSRect)rect
{
[image lockFocus];
[[NScolor whiteColor] set];
[NSBezierPath fillRect:[frameRect]];
[path stroke];
[image unlockFocus];
[image drawInRect: rect
fromRect: rect
operation: NSCompositeCopy
fraction: 1.0];
}
then i get subpixel precision.
so, what's the proper way to achieve offscreen antialising + subpixel
precision in an NSImage that has a background ??? (
http://michelf.com/weblog/2006/subpixel-antialiasing-achilles-heel/
seems to explain why it's impossible to do it with transparent backgrounds)
i guess this is related to graphic contexts but i'm just learning cocoa,
please help :)
regards,
g.
_______________________________________________
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