如何用 alpha < 画线1 英寸石英 2d [英] How do I draw lines with alpha < 1 in quartz 2d

查看:11
本文介绍了如何用 alpha < 画线1 英寸石英 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.

我正在使用普通石英二维码在触摸事件上画线.

I am using normal quartz 2d code to draw line on touch events.

推荐答案

嗨..

这是我的最终解决方案..我现在在 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 &lt; 画线1 英寸石英 2d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆