How do I draw lines with alpha lt; 1 in quartz 2d(如何用 alpha lt; 画线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 < 画线1 英寸石英 2d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何用 alpha < 画线1 英寸石英 2d


基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01