如何画水平线和水平线Quartz 中一像素宽的垂直线?

发布于 2024-09-27 06:49:17 字数 860 浏览 0 评论 0原文

我在绘制一像素宽的线条时遇到问题。所有线条都是完全水平或垂直的(我没有画对角线),但它们画得不干净。看起来它正在以减少的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此刻的回忆 2024-10-04 06:49:17

我的不好。我一发布这篇文章,就在 CGContext 参考指南中找到了答案。我所要做的就是添加一行:

CGContextSetShouldAnitalias(ctx, 0); 

宾果游戏!一切都归于平静……

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:

CGContextSetShouldAnitalias(ctx, 0); 

and bingo! All is at peace...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文