• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: One pixel wide bezier path
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: One pixel wide bezier path
      • From: Eamon Ford <email@hidden>
References: 
 >One pixel wide bezier path (From: Eamon Ford <email@hidden>)

  • Prev by Date: Re: One pixel wide bezier path
  • Next by Date: Re: One pixel wide bezier path
  • Previous by thread: Re: One pixel wide bezier path
  • Next by thread: Re: One pixel wide bezier path
  • Index(es):
    • Date
    • Thread