如何获得1像素线与NSBezierPath? [英] How to get a 1 pixel line with NSBezierPath?

查看:149
本文介绍了如何获得1像素线与NSBezierPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发自定义控件。其中一个要求是画线。虽然这个工作,我注意到,我的1像素宽线不像真正看起来像1像素宽线 - 我知道,他们不是真正的像素,但你知道我的意思。它们看起来更像是两三个像素宽。这在我画一条1像素虚线和2像素间隙的虚线时变得非常明显。

I'm developing a custom control. One of the requirements is to draw lines. Although this works, I noticed that my 1 pixel wide lines do not really look like 1 pixel wide lines - I know, they're not really pixels but you know what I mean. They look more like two or three pixels wide. This becomes very apparent when I draw a dashed line with a 1 pixel dash and a 2 pixel gap. The 1 pixel dashes actually look like tiny lines in stead of dots.

我已经阅读过Cocoa Drawing文档,虽然Apple提到了setLineWidth方法,但将行宽改为

I've read the Cocoa Drawing documentation and although Apple mentions the setLineWidth method, changing the line width to values smaller than 1.0 will only make the line look more vague and not thinner.

因此,我怀疑还有其他影响我的线条外观的方式。

So, I suspect there's something else influencing the way my lines look.

任何想法?

推荐答案

Bezier路径以它们的路径为中心,沿着X坐标绘制一个1像素宽的路径,该线实际上沿着Y坐标{-0.5,0.5}绘制。解决方案通常是将坐标偏移0.5,使得线不在子像素边界中绘制。您应该可以将边界框移动0.5,以获得更清晰的绘图行为。

Bezier paths are drawn centered on their path, so if you draw a 1 pixel wide path along the X-coordinate, the line actually draws along Y-coordinates { -0.5, 0.5 } The solution is usually to offset the coordinate by 0.5 so that the line is not drawn in the sub pixel boundaries. You should be able to shift your bounding box by 0.5 to get sharper drawing behavior.

这篇关于如何获得1像素线与NSBezierPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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