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

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

问题描述

我正在创造一些形状来学习,一切似乎都模糊了,就像一些抗锯齿,我没有使用任何效果(我还没有得到这些课程,哈哈)。

I'm creating some shapes to learn and everything seems to be blurred, like some anti-aliasing, and I´m not using any effects (I don´t get these lessons yet, lol).

例如,我在1像素宽度的黑色背景中绘制一条白线,但它变灰了!如果我将宽度更改为2px,它会变白,但仍然没有真正定义。

For exemple, I draw a white line in a black backgroud with 1 pixel width, but it´s get grey! If I change the width to 2px it gets white, but still not really defined.

当我googleing时,我发现的一切都是一个方法 setSmooth(false)关于形状,但它没有任何区别。我不应该在Stage或Scene上更改或禁用任何我不知道的内容吗?

When I was "googleing" everything I found was a bout a method setSmooth(false) on shapes, but it does not make any difference. Is ther anything I should change or disable on Stage or Scene I don´t know?

任何帮助表示赞赏。感谢您的建议...

Any help is appreciated. Thanks in advice...

对不起我的英语仍然需要改进lol ...但这不是我的自然语言。

Sorry about my english still need improvements too lol... but it´s not my natural language.

推荐答案

参见形状文档:


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

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.

另请参阅的文档节点


在设备像素级别,整数坐标映射到角落
和像素之间的裂缝和像素的中心出现在
整数像素位置之间的中点。因为所有坐标
值都是用浮点数指定的,所以坐标可以
精确指向这些角(当浮点值具有
精确整数值时)或者像素上的任何位置。例如,
坐标(0.5,0.5)将指向舞台上左上角
像素的中心。类似地,在(0,0)处的尺寸为
为10乘10的矩形将从舞台上左上角
像素的左上角跨越到第10像素的右下角。
10th scanline。
矩形内最后一个像素的像素中心位于坐标(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天全站免登陆