简体   繁体   English

JavaFX中填充速度最快的一个像素

[英]The fastest filling one pixel in JavaFX

I use canvas in JavaFX library. 我在JavaFX库中使用canvas。 I need to draw many pixels as fast as possible. 我需要尽可能快地绘制许多像素。 I execute this : 我执行这个:

canvas.getGraphicsContext2D().setFill(color);
canvas.getGraphicsContext2D().fillRect(x, y, 1, 1);

I suppose it is very slow. 我想这很慢。 Can I use faster way? 我可以用更快的方式吗? Maybe should I use another way/method to fill one pixel? 也许我应该使用另一种方式/方法来填充一个像素?

You can use the PixelWriter from an Image. 您可以使用Image中的PixelWriter。 As @jewelsea said use canvas.getGraphicsContext2D().getPixelWriter() 正如@jewelsea所说使用canvas.getGraphicsContext2D()。getPixelWriter()

With the PixelWriter you can paint any Pixel you want: 使用PixelWriter,您可以绘制任何您想要的Pixel:

pixelWriter.setColor(int x, int y,Color c) pixelWriter.setColor(int x,int y,Color c)

I think this is the best way for only Paint pixels. 我认为这是仅有Paint像素的最佳方式。

You can also waive the Canvas and use an ImageView with an WriteAbleImage in it. 您也可以放弃Canvas并使用带有WriteAbleImage的ImageView。

In this case you can use writableImage.getPixelWriter() in the same way as the Canvas. 在这种情况下,您可以使用与Canvas相同的方式使用writableImage.getPixelWriter()

If this is still to slow you can Execute the pixelWriter.setColor(..) in a background Thread so the Application don't stop. 如果这仍然很慢,你可以在后台线程中执行pixelWriter.setColor(..),这样应用程序就不会停止。

See also: 也可以看看:

canvas performance 帆布表现

I hope this answer helps you. 我希望这个答案可以帮到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM