How to get each pixel coordinates of any shape in iPhone

0 votes
asked Jan 13, 2010 by anindya-sengupta

I am using a UIView subclass to draw an alphabet using QuartzCore Framework. Using this code, only hollow characters are drawn (by making the stroke color blue). Here, I need each pixel's position (coordinates) of the character that is added on the current view. Please give me an idea on how can I 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

}

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...