Re: Unwanted transparency in NSBezierPath?
Re: Unwanted transparency in NSBezierPath?
- Subject: Re: Unwanted transparency in NSBezierPath?
- From: Christian Brunschen <email@hidden>
- Date: Sun, 2 Feb 2003 16:17:29 +0000
On Sunday, Feb 2, 2003, at 15:33 Europe/London, Steve wrote:
Hi,
I'm drawing simple, horizontal lines in to a subclass of NSImageView:
in my drawRect method.
[[NSColor blackColor] set];
NSPoint start = NSMakePoint(10,10);
NSPoint end = NSMakePoint(110,10);
NSBezierPath *line = [NSBezierPath bezierPath];
[line setLineWidth:1.0];
[line moveToPoint:start];
[line lineToPoint:end];
[line stroke];
The problem is they are drawing semi-transparent ; I can tell because
they look mid-grey, and gradually become black if I repeat the drawing
2 0r 3 times.
Also, they are drawing 2 pixels thick despite the [line
lineToPoint:end] message;
Are there any graphics-context globals that could be overriding my
code?
Nope. The graphics system is doing exactly what you ask it to do.
The issue is that the coordinate system behaves differently from what
you expect: The integer valued coordinates (in the default coordinate
system) lie precisely on the edges between pixels; and each pixel
covers an area of 1.0 by 1.0 coordinate units:
(x, y+1) (x+1, y+1)
+---------+
| |
| |
| |
+---------+
(x, y) (x+1, y)
Likewise, when you are drawing a line, you will paint pixels to half
the line's width to each side of the line's center. So, by drawing your
line on in integer coordinates, you are drawing it right between
pixels; and by drawing it one unit in width, you are instructing the
graphics system to pain one-half pixel's width to each side of the line
(which as we just discovered, lies precisely between pixels). So what
happens is that both the pixels above and below the line, get
half-painted (due to anti-aliasing).
In order to get the line painted exactly on the pixels themselves, move
your coordinates by 0.5:
NSPoint start = NSMakePoint(10.5, 10.5);
NSPoint end - NSMakePoint(109.5, 10.5);
Thanks
Best wishes,
Steve
// Christian Brunschen
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.