- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在创建一些形状,尽管没有应用任何效果,但一切似乎都很模糊,就像抗锯齿一样。
例如,在黑色背景上绘制的一条宽度为 1 像素的白线呈现为灰色!将宽度更改为 2px 会导致白色,但定义不明确。
搜索时,返回形状上的方法 setSmooth(false)
,但调用它没有任何区别。
我应该在 Stage
或 Scene
上更改或禁用什么?
最佳答案
参见 Shape文档:
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.
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.
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 的文档:
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).
因此,当您的笔画宽度奇数时,您可以选择干净的线条:
至于为什么setSmooth(false)
不起作用,我也不清楚,我的猜测是它所指的抗锯齿独立于当笔划集中在像素之间有裂缝,但我不知道为什么会这样。
关于JavaFX 图形 "blurred"或消除锯齿? (没有使用效果),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9779693/
尝试使用 tkinter 为一系列 PIL 图像制作动画。我的帧持续时间 (ms) 的图表如下所示: 有人知道是什么导致了这种尖尖的锯齿图案吗? 这是一个重现的脚本: from PIL import
我正在尝试使用 Canvas 创建“星爆”效果,但线段出现令人难以置信的像素化。我做错了什么吗? var rays = 40; var canvas = $("header canvas")[0];
爪牙 我在 JAGS 中有一个仅拦截逻辑模型,定义如下: model{ for(i in 1:Ny){ y[i] ~ dbern(mu[s[i]]) } for(j in 1:Ns){
我是一名优秀的程序员,十分优秀!