> On Feb 9, 2015, at 1:18 PM, Jerry Krinock <je...@ieee.org> wrote:
> 
> Is there a way to draw thin lines in code, and get good results on non-Retina 
> displays?  What should I read to learn how?

(The listserv strips image attachments, so we can’t see the pictures.)

The typical problem drawing thin horizontal/vertical lines is that the line 
gets split between pixels, so you get a 2-pixel-wide gray line when what you 
wanted was a 1-pixel black line. The reason this happens is that when you use 
integer coordinates the line is centered on a pixel boundary, so the left half 
of the line is in one pixel and the right half is in another.

Instead, to draw a one-point line, the coordinate on the axis perpendicular to 
the line should end in .5. For example, to draw a vertical line at x=100, the x 
coord of the line should be 100.5. That way you completely fill the pixels at 
x=100 and no others.

(This only applies to odd widths, though. For a 2pt line, you do want 
whole-number coords.)

(It gets more complicated if you’ve transformed the coordinate system, because 
the above considerations apply to device coords, so you’d have to transform 
your drawing coords into device coords, do the rounding/offset, and then back. 
This happens with scaling, but can also occur if you’ve scrolled/offset your 
coordinates by non-integral amounts.)

—Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to