views:

159

answers:

0

I am using UIView subclass to draw an alphabet using QuartzCore Framework.Using this code only hollow characters are drawn(By Making the stroke color- blue color).Here I need each pixel position (coordinates) of the character that is added on current view.Please give me an idea how I will get each pixel point coordinates(Only the blue points in the code below) of the hollow character drawn.

The code is below:

/*UIView Subclass Method*/
- (void)drawRect:(CGRect)rect 
{
      //Method to draw the alphabet
      [self drawChar:@"A" xcoord:5 ycoords:35];
}
-(void)drawChar:(NSString *)str xcoord: (CGFloat)x ycoord: (CGFloat)y
{

    const char *text = [str UTF8String];//Getting the alphabet
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSelectFont(ctx, "Helvetica", 40.0, kCGEncodingMacRoman);
    CGContextSetTextDrawingMode(ctx, kCGTextFillStroke);
    CGContextSetStrokeColorWithColor(ctx, [UIColor blueColor].CGColor);//to make the character hollow-Need only these points
    CGContextSetFillColorWithColor(ctx, [UIColor clearColor].CGColor);//Fill color of character is clear color

    CGAffineTransform xform = CGAffineTransformMake(
                                                    1.0,  0.0,
                                                    0.0, -1.0,
                                                    0.0,  0.0);//Giving a transformation to the alphabet

    CGContextSetTextMatrix(ctx, xform);
   CGContextShowTextAtPoint(ctx, x, y, text, strlen(text));//Generating the character

}