使用 Cobra 进行 Java HTML 渲染
我目前正在使用 Cobra: Java HTML Renderer &用于呈现根据 Java 应用程序中的用户选择动态生成的 HTML 页面的解析器。
在我的应用程序中,用户可以选择数百个项目。这些项目以特殊的独特颜色符号的形式显示,并且用户可以选择多个项目。
一旦选择了多个项目,它们的书面描述就会动态生成并格式化为包括 css2 和 html4 标签,并加载到 Cobra HTMLPanel 中进行显示。
我希望在 HTMLPanel 中显示带有项目书面描述的符号图像。
一种方法是使用 ImageIO.write 将 BufferedImage 保存到文件中,然后将 img html 标签包含在正在加载到 HTMLPanel 中的动态生成的 HTML 文档中。不幸的是,这是不可接受的,因为用户可能选择了数百个符号,这反过来会导致数百个 ImageIO.write 调用,并导致我的应用程序的性能出现令人难以置信的下降。
另一种方法是将 BufferedImage 转换为 Base64 编码,然后直接将编码放入 HTML 文档中,如下所示。
<img alt="Embedded Image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />
不幸的是,HTMLPanel 似乎忽略了数据 URI 方案。
有谁知道解决方案吗?
I am currently using Cobra: Java HTML Renderer & Parser to render an HTML page that is dynamically generated based on user choices in a java app.
In my app the user has a choice of hundreds of items to select. The items are displayed in the form of special uniquely colored symbols and the user can select more then one item.
Once a number of items are selected their written description is dynamically generated and formatted to include css2 and html4 tags and loaded into the Cobra HTMLPanel for display.
I wish to display the image of the symbol with the written description of an item in the HTMLPanel.
One way to do this would be to save the BufferedImage to a file using ImageIO.write and then include the img html tag in my dynamically generated HTML document that is being loaded into HTMLPanel. Unfortunately this is unacceptable as there may be hundreds of symbols being selected by the user wich in turn would result in hundreds of ImageIO.write calls and an incredible decrease in performance of my app.
An alternate way would be to convert the BufferedImage to a Base64 encoding and then directly place the encoding into the HTML document as follows
<img alt="Embedded Image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />
Unfortunately HTMLPanel appears to ignore the data URI scheme.
Does anyone know a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用像 Jetty 这样的嵌入式 servlet 容器。将 URL 指向“http://localhost:somePort/imageId”,然后从内存中提供这些 URL。
Use an embedded servlet container like Jetty. Point the URLs to "http://localhost:somePort/imageId", and then serve those URLs up from memory.