turning off anti-aliasing
turning off anti-aliasing
- Subject: turning off anti-aliasing
- From: Rob Ross <email@hidden>
- Date: Tue, 4 Jul 2006 23:21:21 -0700
Hi. I'm new to Cocoa and Quartz 2D, and I have a question about the
"best" way to temporarily turn off anti-aliasing when drawing in an
NSView subclass.
I am drawing some simple path shapes (circles, squares, sine wave,
etc), and I wanted to draw a cartesian coordinate grid behind them.
But my grid lines were coming out "fuzzy". I was stroking them as 1-
unit wide, but as I resized the Window containing the view, they
would "smear" and every other pixel growth of the window, vertically
or horizontally, I would see the grid lines change from one to two
pixels in width. After doing some research I thought the problem was
due to antialiasing. (Another mystery to me is why, although the
scale factor is 1,1, when I change the size of my window by a single
pixel, the new window size as reported by bounds has increased by .5
of a pixel.)
I tried turning off antialiasing before drawing the grid via
[nsGraphicsContextInstance setShouldAntialias:NO] but that didn't
seem to do anything at all. What is this purpose of this method?
But I found a method in Quartz 2D (or Core Graphics? - not sure what
the proper term is ) that seems to do the trick, so before drawing my
grid lines I call this method:
- (void)setAntialiasing:(BOOL)flag
{
NSGraphicsContext *nsctx = [NSGraphicsContext currentContext];
CGContextRef context = (CGContextRef)[nsctx graphicsPort];
[nsctx setShouldAntialias:flag];
CGContextSetAllowsAntialiasing(context,flag);
}
with YES, and after I draw the grids I call it with NO.
My question is, is there a pure Cocoa way of doing this without using
the CGContextSetAllowsAntialiasing method? Or is this the way I
should be doing it? And why doesn't "setShouldAntialias:NO" by itself
work?
Thanks!
Rob Ross
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden