我想用给定的线条颜色、线条粗细和填充颜色绘制一个三角形。但是有些我无法正确填充三角形。每次三角形周围的整个区域也被填充。
这是我的代码:
+ (UIImage *) drawColorTriangleWithBorderWidth:(int)Width Height:(int)Height R:(int)R G:(int)G B:(int)B A:(int)A BorderR:(int)BR BorderG:(int)BG BorderB:(int)BB BorderA:(int)BA Thickness:(CGFloat)thickness {
if ( Width == 0 || Height == 0) return nil;
float de = thickness/2.0;
UIGraphicsBeginImageContext(CGSizeMake(Width+de, Height+de));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGFloat rr = 1.0*R/255.0; if ( rr > 1.0) rr = 1.0;
CGFloat gg = 1.0*G/255.0; if ( gg > 1.0) gg = 1.0;
CGFloat bb = 1.0*B/255.0; if ( bb > 1.0) bb = 1.0;
CGFloat aa = 1.0*A/100.0; if ( aa > 1.0) aa = 1.0;
CGFloat brr = 1.0*BR/255.0; if ( brr > 1.0) brr = 1.0;
CGFloat bgg = 1.0*BG/255.0; if ( bgg > 1.0) bgg = 1.0;
CGFloat bbb = 1.0*BB/255.0; if ( bbb > 1.0) bbb = 1.0;
CGFloat baa = 1.0*BA/100.0; if ( baa > 1.0) baa = 1.0;
CGContextSetLineCap(context, kCGLineCapSquare);
CGContextSetRGBFillColor(context, rr, gg, bb, aa);
CGContextSetLineWidth(context, thickness);
CGContextSetRGBStrokeColor(context, brr, bgg, bbb, baa);
CGContextMoveToPoint(context, Width/2.0, de);
CGContextAddLineToPoint(context, de, Height-de);
CGContextAddLineToPoint(context, Width-de, Height-de);
CGContextAddLineToPoint(context, Width/2.0, de);
CGContextDrawPath(context, kCGPathFillStroke);
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
谁能帮我?谢谢。