views:

14

answers:

1

Hi, I am having trouble drawing one pixel wide lines. All lines are perfectly horizontal or vertical (I am not drawing diagonal lines) but they do not draw cleanly. It looks like it is drawing across two pixels at a reduced alpha. No doubt due to antialiasing. I've searched the docs and forums and have come across a statement saying that there's "...no problem drawing horizontal and vertical lines one pixel wide..." but I don't know how exactly. Any pointers would be welcome.

The drawing code is simple:

else if ([[value entity].name isEqualToString:@"RTLine"]) {

CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1);
CGContextSetLineWidth(ctx, [[value valueForKey:@"thickness"] doubleValue]);
CGContextMoveToPoint(ctx, [[value valueForKey:@"beginDrawLocationX"] doubleValue],
                             [[value valueForKey:@"beginDrawLocationY"] doubleValue]);
CGContextAddLineToPoint(ctx, [[value valueForKey:@"endDrawLocationX"] doubleValue],
                                [[value valueForKey:@"endDrawLocationY"] doubleValue]);
CGContextStrokePath(ctx);

}

In the above, 'thickness' is equal to 1. I used doubleValue instead of floatValue for conversion from int in case float was mushing the value to something not quite 1 - it wasn't.

+1  A: 

My bad. As soon as I posted this I found the answer in the CGContext reference guide. all I had to do is add the line:

CGContextSetShouldAnitalias(ctx, 0); 

and bingo! All is at peace...

skajam66
+1 self answers are good. You can also "accept" your own answer to mark this question as answered.
msw