Re: One pixel width. One.
Re: One pixel width. One.
- Subject: Re: One pixel width. One.
- From: Graham Cox <email@hidden>
- Date: Fri, 25 Apr 2008 17:34:44 +1000
Try offsetting the final result by 0.5, so that you draw the actual
pixel, not anti-alias across two.
G.
On 25 Apr 2008, at 5:19 pm, Lorenzo 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 scale the
view
with
NSRect frameSize = [self frame].size;
NSSize newSize = NSMakeSize(frameSize.width / mScaleFactor,
frameSize .height / mScaleFactor);
[self setBoundsSize:newSize];
In the drawRect method I code
[[NSGraphicsContext currentContext] setShouldAntialias:NO];
[NSBezierPath setDefaultLineWidth:1.0 / mScaleFactor];
[NSBezierPath strokeLineFromPoint:NSMakePoint(0.0, 10.0
toPoint:NSMakePoint(10.0, 10.0)];
I works pretty well, but sometimes, depending on the scroll position
or the
mScaleFactor, I get a line with 2 pixels width. Even with a
mScaleFactor =
1, if I scroll the view, sometimes it looks with 2 pixels width. I
even
tried to always set the width to 0.1 and mScaleFactor to always 1.
Same
result. And I even tried to always set bounds Origin and bounds Size
to
(int) values. Same result.
What do I miss?
Best Regards
--
Lorenzo
email: email@hidden
_______________________________________________
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
_______________________________________________
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