将 JavaFX 图像转换为 BufferedImage

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21540378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 09:15:39  来源:igfitidea点击:

Convert JavaFX image To BufferedImage

javaimageviewjavafxbufferedimage

提问by Piet Jetse

I'm trying to convert an JavaFXImage(from ImageView) to an BufferedImage. I tried casting and stuff but nothing works. Can someone suggest how i should do this?

我正在尝试将JavaFXImage(from ImageView) 转换为BufferedImage. 我试过铸造和东西,但没有任何效果。有人可以建议我应该怎么做吗?

采纳答案by lukk

Try your luck with SwingFXUtils. There is a method for that purpose:

试试你的运气SwingFXUtils。有一种方法可以用于此目的:

BufferedImage fromFXImage(Image img, BufferedImage bimg)

You can call it with second parameter null, as it is optional (exists for memory reuse reason):

您可以使用第二个参数调用它null,因为它是可选的(存在内存重用原因):

BufferedImage image = SwingFXUtils.fromFXImage(fxImage, null);