【发布时间】:2012-06-23 23:14:47
【问题描述】:
以下方法应该创建一个 FILLED 三角形图像,但它只创建一个轮廓。 为什么它不填充?和这个一起疯了。我希望它得到答复,以便下一个为此苦苦挣扎的可怜人可以清除障碍并节省一个小时的生命。
这是我写的方法:
+ (UIImage *)triangleWithSize:(CGSize)imageSize
{
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(context, YES);
// set parameters
CGContextSetLineWidth(context, 1);
CGContextSetStrokeColorWithColor(context, [UIColor yellowColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColor yellowColor].CGColor);
// draw triangle
CGContextBeginPath(context);
CGContextMoveToPoint(context, imageSize.width, 0);
CGContextAddLineToPoint(context, imageSize.width, imageSize.height);
CGContextMoveToPoint(context, imageSize.width, imageSize.height);
CGContextAddLineToPoint(context, 0, imageSize.height / 2);
CGContextMoveToPoint(context, 0, imageSize.height / 2);
CGContextAddLineToPoint(context, imageSize.width, 0);
// CGContextFillPath(context);
// CGContextClosePath(context);
// stroke and fill?
CGContextDrawPath(context, kCGPathFillStroke);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsPopContext();
return image;
}
感谢任何帮助。
【问题讨论】:
-
我只是将 UIGraphicsBeginImageContextWithOptions 的第二个参数设置为 YES 以使其不透明思考 YUREKA!但是很可惜,这不起作用。