MiTal Khandhar
MiTal Khandhar

Reputation: 285

How to make sharp border of shape in CGrect?

I am using CGrect to draw circle with border but i didn't get sharp border of circle here is my code:

 CGRect rect = CGRectMake(lastPoint1.x - CircleRadius ,lastPoint1.y - CircleRadius,CircleDia,CircleDia);
    CGContextSetFillColorWithColor(ctx, [Util_color getThemeColor].CGColor);
    CGContextFillEllipseInRect(ctx, rect);
    CGContextSetRGBStrokeColor(ctx, 255.0, 255.0, 255.0, 1.0);
    CGContextStrokeEllipseInRect(ctx, rect);
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(ctx, 3.0);
     CGContextSetShouldAntialias(ctx, YES);
    CGContextSetLineCap(cox,kCGLineCapRound);

but i still get blur border ! Is there any way to get sharp border using CGrect?

Upvotes: 1

Views: 180

Answers (2)

uliwitness
uliwitness

Reputation: 8793

You're drawing between pixels. See here for an explanation and a fix: http://orangejuiceliberationfront.com/are-your-rectangles-blurry-pale-and-have-rounded-corners/

(This is a duplicate of How to get a 1 pixel line with NSBezierPath? for which I wrote this explanation originally)

Upvotes: 2

danh
danh

Reputation: 62676

Guessing that what the OP means by sharp border is one that hasn't had anti-aliasing applied.

CGContextSetShouldAntialias(ctx, NO);

Upvotes: 0

Related Questions