【发布时间】:2015-03-10 06:03:17
【问题描述】:
我正在使用 UIView 子类使用 Core Graphics 绘制字母表。使用此代码,只有空心字符是 drwan(通过使笔触颜色为黑色)。这里我需要字符的每个像素(坐标)位置。请给出我知道如何获取空心字符的每个像素点(仅黑点的像素值)。
源代码:
/*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 blackColor].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
}
【问题讨论】:
标签: iphone cocoa-touch core-graphics