Re: One pixel wide bezier path
Re: One pixel wide bezier path
- Subject: Re: One pixel wide bezier path
- From: Joshua Scott Emmons <email@hidden>
- Date: Wed, 25 Jan 2006 15:07:26 -0600
I can't make a 1 pixel wide bezier path;
This is probably happening because your path is going down the middle
of two pixels. When NSBezierPath goes to stroke it, it has to split
the difference between the two pixels. This results in anti-aliasing
and a line that is semi-transparent and 2-pixels wide.
Here's an example: Make a custom view and give it a -drawRect: like
the following.
-(void)drawRect:(NSRect)rect{
NSBezierPath *path = [NSBezierPath bezierPathWithRect:NSMakeRect
(5,5,20,20)];
[NSBezierPath setDefaultLineWidth:1];
[[NSColor blackColor]set];
[path stroke];
}
The result will be a 20x20 black square with fuzzy 2px borders. Now
try it with:
-(void)drawRect:(NSRect)rect{
NSBezierPath *path = [NSBezierPath bezierPathWithRect:NSMakeRect
(5.5,5.5,20,20)];
[NSBezierPath setDefaultLineWidth:1];
[[NSColor blackColor]set];
[path stroke];
}
You'll have a 20x20 square with nice solid borders because instead of
drawing in between pixels (x:5, y:5) you're drawing right down the
middle of pixels (x:5.5, y:5.5).
Check out NSBezierPath's docs for -setDefaultLineWidth:
"...The actual rendered line width may vary from width by as much as
2 device pixels, depending on the position of the line with respect
to the pixel grid. The width of the line may also be affected by
scaling factors specified in the current transformation matrix of the
active graphics context."
Cheers,
-Joshua Emmons
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden