FROM : Gregory 'guardian' Pakosz
DATE : Wed Jan 09 12:40:38 2008
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.
DATE : Wed Jan 09 12:40:38 2008
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.
| Related mails | Author | Date |
|---|---|---|
| Gregory 'guardian'… | Jan 9, 12:40 | |
| Jonathon Mah | Jan 9, 13:01 | |
| Gregory 'guardian'… | Jan 9, 13:34 | |
| Jean-Daniel Dupas | Jan 9, 13:49 | |
| Jonathon Mah | Jan 9, 18:20 | |
| John Stiles | Jan 9, 18:28 | |
| Ken Ferry | Jan 10, 00:23 | |
| Ricky Sharp | Jan 10, 02:27 | |
| Alastair Houghton | Jan 10, 12:44 |






Cocoa mail archive

