JavaFX 图形“模糊"或抗锯齿?(没有使用效果) [英] JavaFX graphics "blurred" or anti-aliased? (No effects used)

查看:27
本文介绍了JavaFX 图形“模糊"或抗锯齿?(没有使用效果)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一些形状,尽管没有应用任何效果,但一切似乎都很模糊,就像抗锯齿一样.

I'm creating some some shapes and everything seems to be blurred, like anti-aliased despite no effects applied.

例如,在黑色背景上以 1 像素宽度绘制的白线呈现为灰色!将宽度更改为 2px 会导致白色,但定义不明确.

For example, a white line drawn on a black backgroud with 1 pixel width, is rendered grey! Changing the width to 2px results in white, but not well-defined.

搜索时,返回了形状上的 setSmooth(false) 方法,但调用它没有任何区别.

When searching, the method setSmooth(false) on shapes returned, but calling it makes no difference.

我应该在 StageScene 上更改或禁用哪些内容?

What should I change or disable on Stage or Scene?

推荐答案

参见 形状 文档:

大多数节点倾向于只对它们应用整数转换,并且通常它们也使用整数坐标定义.为了在这种常见情况下,具有直线边缘的形状的填充往往是清晰,因为它们与落在的像素之间的裂缝对齐整数设备坐标,因此倾向于自然地覆盖整个像素.

Most nodes tend to have only integer translations applied to them and quite often they are defined using integer coordinates as well. For this common case, fills of shapes with straight line edges tend to be crisp since they line up with the cracks between pixels that fall on integer device coordinates and thus tend to naturally cover entire pixels.

另一方面,抚摸这些相同的形状通常会导致模糊大纲,因为默认的描边属性指定默认笔画宽度为 1.0 坐标,通常映射到 1设备像素,并且笔画应该跨越边界形状,在边界的两侧下降一半.由于许多常见形状的边框往往直接落在整数上坐标和那些整数坐标通常精确映射到整数设备位置,边界往往会导致 50% 的覆盖率在边框两侧的像素行和列上形状而不是 100% 覆盖一个或另一个.因此,填充可能通常很清晰,但笔画通常很模糊.

On the other hand, stroking those same shapes can often lead to fuzzy outlines because the default stroking attributes specify both that the default stroke width is 1.0 coordinates which often maps to exactly 1 device pixel and also that the stroke should straddle the border of the shape, falling half on either side of the border. Since the borders in many common shapes tend to fall directly on integer coordinates and those integer coordinates often map precisely to integer device locations, the borders tend to result in 50% coverage over the pixel rows and columns on either side of the border of the shape rather than 100% coverage on one or the other. Thus, fills may typically be crisp, but strokes are often fuzzy.

避免这些模糊轮廓的两种常见解决方案是使用更广泛的完全覆盖更多像素的笔画 - 通常是笔画宽度如果没有有效的比例变换,2.0 将实现这一点 -或指定 StrokeType.INSIDE 或 StrokeType.OUTSIDE笔画样式 - 将默认的单个单位笔画偏向全像素行或列之一就在其内部或外部形状的边框.

Two common solutions to avoid these fuzzy outlines are to use wider strokes that cover more pixels completely - typically a stroke width of 2.0 will achieve this if there are no scale transforms in effect - or to specify either the StrokeType.INSIDE or StrokeType.OUTSIDE stroke styles - which will bias the default single unit stroke onto one of the full pixel rows or columns just inside or outside the border of the shape.

另见Node的文档:

在设备像素级别,整数坐标映射到角落并且像素和像素中心之间的裂缝出现在整数像素位置之间的中点.因为都是坐标值用浮点数指定,坐标可以精确地指向这些角(当浮点值有精确的整数值)或像素上的任何位置.例如,一个(0.5, 0.5) 的坐标将指向左上角的中心舞台上的像素.类似地,在 (0, 0) 处的矩形尺寸为10 x 10 将从左上角的左上角跨越舞台上第 10 个像素右下角的像素第 10 条扫描线.里面最后一个像素的像素中心矩形将在坐标 (9.5, 9.5) 处.

At the device pixel level, integer coordinates map onto the corners and cracks between the pixels and the centers of the pixels appear at the midpoints between integer pixel locations. Because all coordinate values are specified with floating point numbers, coordinates can precisely point to these corners (when the floating point values have exact integer values) or to any location on the pixel. For example, a coordinate of (0.5, 0.5) would point to the center of the upper left pixel on the Stage. Similarly, a rectangle at (0, 0) with dimensions of 10 by 10 would span from the upper left corner of the upper left pixel on the Stage to the lower right corner of the 10th pixel on the 10th scanline. The pixel center of the last pixel inside that rectangle would be at the coordinates (9.5, 9.5).

因此,当您的笔画宽度为奇数时,您可以选择的干净线条是:

So your options for clean lines when you have an odd stroke width are:

  1. 使用 StrokeType.INSIDE 或 StrokeType.OUTSIDE 笔触样式.
  2. 将形状的坐标偏移 0.5 个像素,使笔划在线条上对齐,而不是线条之间的裂缝.
  3. 只需使用下一个偶数作为笔画宽度,例如1 => 2、3 => 4 等

至于为什么 setSmooth(false) 不起作用,我不确切知道,我的猜测是它所指的抗锯齿与当笔画居中时执行的抗锯齿样式无关像素之间出现裂缝,但我不知道为什么会这样.

As to why setSmooth(false) does not work, I don't know exactly, my guess is that the antialiasing it refers to is independent of the antialiasing styles performed when strokes are centered on the cracks between pixels, but I would not know why that would be.

这篇关于JavaFX 图形“模糊"或抗锯齿?(没有使用效果)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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