• 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: Drawing 1 pixel line with zoom change
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing 1 pixel line with zoom change


  • Subject: Re: Drawing 1 pixel line with zoom change
  • From: Graham Cox <email@hidden>
  • Date: Tue, 12 May 2009 14:23:03 +1000


On 12/05/2009, at 12:44 AM, Sahana A wrote:

We have a feature in our application wherein we have to draw a 1 pixel line. This drawing also varies relative to the zoom factor of our view. For example
if we are drawing at a zoom factor of 200% we draw 0.5 pixel line. ( basically: 1/zoomfactor width of line; 1 if the zoomfactor < 100 ).


For most of the times we succeed in drawing the 1 pixel line. However after we change the zoom factor, our drawing fails. Our 1 pixel
line is now drawn in 2 pixels.
For example: On changing the zoom values from say 100% to 300% and back to 100% again, the single pixel line sometimes draw in 2 pixels.
Even if the stroke width is set to 0.0 or 1.0, the stroked line will draw 2 pixels.


It's not just a case of setting the line width, but also of placing the line where you want it. Strokes are placed so that they are centred on the co-ordinate, so half the line is above and half below the integral co-ordinate position. This is true even if you suppress anti-aliasing, which make matters worse since the lightening of the line is disabled and it'll draw as a solid 2 pixel line.

You need to truncate the line's co-ordinates to a whole number then add or subtract 0.5 so that the line is drawn on the pixel, not on the co-ordinate.

--Graham


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Drawing 1 pixel line with zoom change
      • From: Kai BrĂ¼ning <email@hidden>
References: 
 >Drawing 1 pixel line with zoom change (From: Sahana A <email@hidden>)

  • Prev by Date: instance management in IB
  • Next by Date: Re: beginner's question: having problems with saving/loading
  • Previous by thread: Drawing 1 pixel line with zoom change
  • Next by thread: Re: Drawing 1 pixel line with zoom change
  • Index(es):
    • Date
    • Thread