如何画水平线和水平线Quartz 中一像素宽的垂直线?
我在绘制一像素宽的线条时遇到问题。所有线条都是完全水平或垂直的(我没有画对角线),但它们画得不干净。看起来它正在以减少的 Alpha 跨两个像素进行绘制。毫无疑问是由于抗锯齿。我搜索了文档和论坛,发现了一个声明,说“......绘制一个像素宽的水平和垂直线没有问题......”但我不知道到底是怎么回事。欢迎任何指点。
绘图代码很简单:
else if ([[value entity].name isEqualToString:@"RTLine"]) {
CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1);
CGContextSetLineWidth(ctx, [[value valueForKey:@"thickness"] doubleValue]);
CGContextMoveToPoint(ctx, [[value valueForKey:@"beginDrawLocationX"] doubleValue],
[[value valueForKey:@"beginDrawLocationY"] doubleValue]);
CGContextAddLineToPoint(ctx, [[value valueForKey:@"endDrawLocationX"] doubleValue],
[[value valueForKey:@"endDrawLocationY"] doubleValue]);
CGContextStrokePath(ctx);
}
在上面,“厚度”等于 1。我使用 doubleValue 而不是 floatValue 来从 int 进行转换,以防 float 将值压缩到不完全为 1 的值 - 事实并非如此。
I am having trouble drawing one pixel wide lines. All lines are perfectly horizontal or vertical (I am not drawing diagonal lines) but they do not draw cleanly. It looks like it is drawing across two pixels at a reduced alpha. No doubt due to antialiasing. I've searched the docs and forums and have come across a statement saying that there's "...no problem drawing horizontal and vertical lines one pixel wide..." but I don't know how exactly. Any pointers would be welcome.
The drawing code is simple:
else if ([[value entity].name isEqualToString:@"RTLine"]) {
CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1);
CGContextSetLineWidth(ctx, [[value valueForKey:@"thickness"] doubleValue]);
CGContextMoveToPoint(ctx, [[value valueForKey:@"beginDrawLocationX"] doubleValue],
[[value valueForKey:@"beginDrawLocationY"] doubleValue]);
CGContextAddLineToPoint(ctx, [[value valueForKey:@"endDrawLocationX"] doubleValue],
[[value valueForKey:@"endDrawLocationY"] doubleValue]);
CGContextStrokePath(ctx);
}
In the above, 'thickness' is equal to 1. I used doubleValue instead of floatValue for conversion from int in case float was mushing the value to something not quite 1 - it wasn't.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的不好。我一发布这篇文章,就在 CGContext 参考指南中找到了答案。我所要做的就是添加一行:
宾果游戏!一切都归于平静……
My bad. As soon as I posted this I found the answer in the CGContext reference guide. all I had to do is add the line:
and bingo! All is at peace...