• 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 width. One.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: One pixel width. One.


  • Subject: Re: One pixel width. One.
  • From: Lorenzo <email@hidden>
  • Date: Fri, 25 Apr 2008 17:58:22 +0200

Joe, thank you. That page helps. I succeeded, but I had to set the width to
0.01 because if I set it to zero I get a 2 pixels thick line when the scale
is different than 1.0. Don't know why. Please follow me.

After scaling the view with

  scale = 1.33;
  [self setBoundsSize:NSMakeSize((int)([self frame].size.width  / scale),
                                 (int)([self frame].size.height / scale))];

I get these logs in the drawRect method

    scale 1.33
    frame {{0, 0}, {1166, 1253}},
    bounds {{-140, -50}, {875, 941}}

As you can see the frame and bounds values are all integers now.
Now I draw a vertical line

    [NSBezierPath setDefaultLineWidth:0.0];
    bot = NSMakePoint(0.5, 0.5);
    top = NSMakePoint(0.5, 9.5);
    [NSBezierPath strokeLineFromPoint:bot toPoint:top];

And the lines looks 2 pixels thick. Dam! So I tried to set

    [NSBezierPath setDefaultLineWidth:0.01 / scale];

And it worked at any scale. Can't guess why! With 0.001 I don't see any
line. Strange story, it works with zero, with 0.01/1.33 and it doesn't work
with 0.001 / 1.33. Any idea?


Best Regards
--
Lorenzo
email: email@hidden

> From: Joe Goh <email@hidden>
> Date: Fri, 25 Apr 2008 17:31:17 +0800
> To: email@hidden, Lorenzo <email@hidden>
> Subject: Re: One pixel width. One.
>
> On 4/25/08, Lorenzo <email@hidden> wrote:
>>  I am trying to draw a line with 1 pixel width. No matter whether the view is
>>  scaled or scrolled, I want to see a 1 pixel thick line.
>
> I highly, highly recommend reading this article:
> http://wincent.com/a/about/wincent/weblog/archives/2007/01/offbyone.php
>
> I wanted to do the exact same thing in my app last year and this
> article saved the day for me.
>
> HTH,
> Joe Goh
> FunkeeMonk Technology
> http://www.funkeemonk.com/

_______________________________________________

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: One pixel width. One.
      • From: Graham Cox <email@hidden>
References: 
 >Re: One pixel width. One. (From: "Joe Goh" <email@hidden>)

  • Prev by Date: Re: Weird Problem With CGImage
  • Next by Date: Re: QTMovie grabing while playback
  • Previous by thread: Re: One pixel width. One.
  • Next by thread: Re: One pixel width. One.
  • Index(es):
    • Date
    • Thread