如何绘制alpha<行? 1英寸石英2d [英] How do I draw lines with alpha < 1 in quartz 2d
问题描述
毫无疑问,这可能是一个重复的问题,但我无法从此处的任何帖子中获得适当的解决方案。所以我发布这篇文章作为新帖子,希望我得到一些解决方案。
No doubt this might be a duplicate question but I am not able to get proper solution from any post here. So I am posting this as new post with a hope that I get some solution.
我的绘图应用程序我想给出一个不透明度的特征来绘制线条。
但是当我将alpha分配给颜色时,我在线之间得到了重叠点。
I my drawing app I want to give a feature of opacity for lines to be drawn. But when I assign alpha to color, I am getting overlapped points in between the line.
我发现两个视图中的绘图解决了这个问题,但我无法理解背后的逻辑。
Some where I found that drawing in two views solves this issue, but I was not able to understand the logic behind that.
我使用普通的石英2d代码在触摸事件上绘制线条。
I am using normal quartz 2d code to draw line on touch events.
推荐答案
Hie ..
这是我的最终解决方案..
我现在在drawRect事件上绘制线条并一次绘制整条线路作为路径..
这会创建不透明度以保留,现在之间没有绘制线帽..
This is my final solution.. I am now drawing lines on drawRect event and drawing the entire line at a time as a path.. This creates opacity to retain and now no line caps drawn in between..
毫无疑问,这是一个有效的伎俩,因为我每次触摸都是有效的,而且这很有效..
No doubt this is the trick that is working since I am drawing on every touch and this works..
- (void)drawRect:(CGRect)rect {
for (int j=0; j<[pathArray count]; j++)
{
context = UIGraphicsGetCurrentContext();
NSMutableDictionary *tmp=[pathArray objectAtIndex:j];
NSMutableArray *currentPath=[tmp objectForKey:@"path"];
for (int i=0; i<[currentPath count]; i++)
{
CGPoint mid1 = [[self midPoint:[currentPath objectAtIndex:i+1] :[currentPath objectAtIndex:i]] CGPointValue];
CGPoint mid2 = [[self midPoint:[currentPath objectAtIndex:i+2] :[currentPath objectAtIndex:i+1]] CGPointValue];
CGContextMoveToPoint(context, mid1.x, mid1.y);
CGContextAddQuadCurveToPoint(context, [[currentPath objectAtIndex:i+1] CGPointValue].x, [[currentPath objectAtIndex:i+1] CGPointValue].y, mid2.x, mid2.y);
CGContextSetShadow(context, CGSizeMake(-2, -2), 3);
CGContextSetAlpha(context, [[tmp objectForKey: @"opacity"] floatValue]);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetStrokeColorWithColor(context,[[tmp objectForKey: @"Color"] CGColor]);
CGContextSetLineWidth(context, [[tmp objectForKey: @"width"] floatValue]);
i+=2;
}
CGContextStrokePath(context);
}
}
这篇关于如何绘制alpha<行? 1英寸石英2d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!