简体   繁体   English

如何在JavaFX WebView组件中加载本地图像

[英]How to load a local image in JavaFX WebView component

I have a set of BufferedImage objects I want to load into my JavaFX WebView (as images that I can paint to the canvas). 我有一组BufferedImage对象,我想将它们加载到JavaFX WebView中(作为可以绘制到画布上的图像)。 It's easy to load HTML and execute JS whenever you need to, but I'm wondering what the best way of getting a BufferedImage into a HTMLImage is. 在需要时加载HTML和执行JS很容易,但是我想知道将BufferedImage转换为HTMLImage的最佳方法是什么。 Would you recommend : 您会推荐:

1) Saving the file as a .jpg and using the file:// prefix 1)将文件另存为.jpg并使用file://前缀

2) Some other way to load the image info the web engine. 2)通过其他方式将图像信息加载到Web引擎。

1 Saving the file as a .jpg and using the file:// prefix 1将文件另存为.jpg并使用file://前缀

This is likely going to be easiest. 这可能是最简单的。

When in doubt, I'd always recommend the easiest solution :-) 如有疑问,我总是建议最简单的解决方案:-)

2 Some other way to load the image info the web engine. 2通过其他方式将图像信息加载到Web引擎。

This is likely to be harder. 这可能会更困难。

One possibility is to define your own protocol handler such as outlined in a New Era for Java Protocol Handlers . 一种可能性是定义自己的协议处理程序,如Java协议处理程序新时代中概述的那样。 Then you can use your custom protocol to fetch the image bits to the WebView. 然后,您可以使用自定义协议将图像位提取到WebView。 This process, if done right will, will eliminate the need for disk I/O. 如果正确执行此过程,将消除对磁盘I / O的需求。

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

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