2009-06-01 49 views
0

为什么下面的代码导致块状渐变?即渐变不平滑,您可以看到一些构成它的矩形。如何在大表面上制作平滑的JavaFX LinearGradient?

有没有办法解决这个问题?
顺便说一句我在Vista上运行这个,但我也在Mac上体验过这一点。

var stage:Stage = Stage { 
title: "Louis' Photo Wall" 
width: 900 
height: 600 

scene: Scene { 
    content : Rectangle { 
     width: bind stage.scene.width 
     height: bind stage.scene.height 
     fill:LinearGradient { 
      startX : 0.0 
      startY : 0.0 
      endX : 0.0 
      endY : 1.0 
      stops: [ 
       Stop { 
        color : Color { 
         red:0.0 
         blue:0.0 
         green:0.0 
        } 

        offset: 0.0 
       }, 
       Stop { 
        color : Color { 
         red:0.8 
         blue:0.8 
         green:0.8 
        } 
        offset: 1.0 
       }, 

      ] 
     } 

    }//OuterRectangle 
} 

}

+0

我没有看到这个问题,当我在Windows XP系统上运行的Java 1.6.0_11的NetBeans 6.5下的代码。 LinearGradient产品光滑 - 不是块状的。调整大小保持整个窗口的渐变。我使用的显示器是三星214T(1600x1200驱动)。 – Refactor 2009-06-01 17:16:57

+0

更新,我确实看到它,但块状效果并不显着。查看提交的答案。 – Refactor 2009-06-01 18:24:10

回答

1

的块状量不显着。

移动到1.0的endX似乎给出了一个更明显的变化与块状结果的对角化。

一个假设是,有几件事情正在进行。 1. r/g/b颜色并非真正连续,而是有256个步骤。 (8位)。 255中的一个是204. 2.如果将0到0.8之间的颜色映射为600像素,则每个像素的增量不能完全平滑。当我跑步时,场景大小实际上是792x566。所以渐变将使用一个颜色566/204 = 2.775像素,然后转移到下一个。导致转换的地方出现波动。

这并不能解释为什么使用0.0到1.0代替0.0到0.8的结果(至少在我的运行中)看起来是一个平稳的过渡。


后续:有是的LinearGradient可能使用插值的方法ofTheWay。一个代码示例和结果...

for (v in [0.00..1.00 step 1.0/600]) { 
    println("{%7.5f v} {Color.WHITE.ofTheWay(Color.BLACK,v)}"); 
} 

它打印

0.00000 javafx.scene.paint.Color[red=255,green=255,blue=255,opacity=1.0] 
0.00167 javafx.scene.paint.Color[red=255,green=255,blue=255,opacity=1.0] 
0.00333 javafx.scene.paint.Color[red=254,green=254,blue=254,opacity=1.0] 
0.00500 javafx.scene.paint.Color[red=254,green=254,blue=254,opacity=1.0] 
0.00667 javafx.scene.paint.Color[red=253,green=253,blue=253,opacity=1.0] 
0.00833 javafx.scene.paint.Color[red=253,green=253,blue=253,opacity=1.0] 
0.01000 javafx.scene.paint.Color[red=252,green=252,blue=252,opacity=1.0] 
0.01167 javafx.scene.paint.Color[red=252,green=252,blue=252,opacity=1.0] 
0.01333 javafx.scene.paint.Color[red=252,green=252,blue=252,opacity=1.0] 
0.01500 javafx.scene.paint.Color[red=251,green=251,blue=251,opacity=1.0] 
0.01667 javafx.scene.paint.Color[red=251,green=251,blue=251,opacity=1.0] 
...