ios - CoreGraphics画线时模糊的问题
巴扎黑
巴扎黑 2017-04-17 11:38:14
0
1
373

我看CoreGraphics的教程时,里面提到1像素绘图模糊的问题,需要偏移0.5点才行。这是为什么呢?stroke path不是stroke在边界上吗?

It turns out that when Core Graphics strokes a path, it draws the stroke on the middle of the exact edge of the path.

这句话要怎么理解呢?

巴扎黑
巴扎黑

全員に返信 (1)
迷茫

在Xcode搜索CGContextSetLineWidth的文档,上面有提到:

The default line width is 1 unit. When stroked, the line straddles the path, with half of the total width on either side.

就是说如果设置宽度为1个像素的线,那么绘制线条分别在所绘路径的两边,每边各一半宽度,即0.5像素。而正在在屏幕上绘制时,是以像素为单位绘制的,并且对于显示内容不满一个像素时,为了平滑显示内容默认使用了抗锯齿效果。如下面中间图形所示,对于1个像素宽度蓝色的线条,左右个0.5像素,剩下0.5像素使用抗锯齿,用淡蓝色绘制。

要解决这个问题,你可以让你的path偏移0.5像素,或者关闭抗锯齿:CGContextSetAllowsAntialiasing(contextRef,NO);

参考答案来源:

  • Quartz 2D - 绘线

  • Core Graphics 101: 线,矩形和渐变效果

いいねを押す+0
    最新のダウンロード
    詳細>
    ウェブエフェクト
    公式サイト
    サイト素材
    フロントエンドテンプレート
    私たちについて 免責事項 Sitemap
    PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!