Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing Thin Lines in Core Graphics



On Thursday, February 28, 2002, at 09:01 AM, Nick Nallick wrote:

I'm trying to draw horizontal and/or vertical lines that are a single pixel wide into a Core Graphics context on the screen. I'm creating a path containing a line and stroking it. Unfortunately I don't seem to be able to draw a line any thinner than two pixels wide. If I specify a smaller stroke width the color of the line become lighter but it's still two pixels wide.

How do I get lines that are one pixel wide in CG?

The CoreGraphics pen surrounds the pen position, unlike Quickdraw, where the pen draws below and to the right of the pen position. In other words, when CG draws a one-pixel-wide line, it draws half of it above the pen position, and half of it below the pen position.

Therefore, if the pen position is at (h=0,v=10) and you draw a horizontal line to (20,10), the pen actually covers the area from v=9.5 to v=10.5. That causes the physical pixels in memory in rows 9 and 10 of the context to be marked - thus the two-pixel-wide line.

To get a one-pixel-wide-line, you need to set the pen position to the middle of the pixel. So if you draw a line from (h=0,v=10.5) to (h=20,v=10.5), you'll get a one-pixel-wide line in row 10 of the image.

-eric
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Drawing Thin Lines in Core Graphics (From: Nick Nallick <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.