LWUIT HtmlComponent 渲染本地图像

发布于 2024-12-04 09:24:17 字数 946 浏览 2 评论 0原文

我想渲染我使用 html 组件在本地创建的内容,并通过将图像放入 jar 中的 res 文件夹中来将图像放入此 html 中,我尝试了

但没有任何效果,有什么建议吗?

[编辑] 这是我的代码,我不知道如何实现 DocumentRequestHandler 这就是我使用 DefaultDocumentRequestHandler

        DocumentRequestHandler handler = new DefaultDocumentRequestHandler();
        HTMLComponent component = new HTMLComponent(handler);
        component.getStyle().setBorder(Border.createLineBorder(1));

        component.getSelectedStyle().setBorder(Border.createLineBorder(1));
        component.setBodyText("<div><b>nirmal:</b>" +
                "<img src='res://images/down.png' /></div>");

尝试 res://images/down.png 的原因但也没有工作 我的图像位于 res/images

I want to render content that i have created locally using html component and put image in this html also by putting image in res folder in jar, i tried

<img src='images/down.png'></img>

<img src='res/images/down.png'></img>

<img src='./images/down.png'></img>

but nothing worked, any suggestion?

[EDIT]
here is my code, i have no idea how to implement DocumentRequestHandler that is why i used DefaultDocumentRequestHandler

        DocumentRequestHandler handler = new DefaultDocumentRequestHandler();
        HTMLComponent component = new HTMLComponent(handler);
        component.getStyle().setBorder(Border.createLineBorder(1));

        component.getSelectedStyle().setBorder(Border.createLineBorder(1));
        component.setBodyText("<div><b>nirmal:</b>" +
                "<img src='res://images/down.png' /></div>");

tried res://images/down.png but nor worked
my image is in res/images

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞陪衬 2024-12-11 09:24:17

您需要解释如何加载 HTML,图像是相对于基本 URL 加载的,因此您需要在创建 HTML 时定义基本 URL(通过 URL 加载时会隐式检测到)。

如果您通过 setHTML(String) 创建 HTML,那么您需要根据您的 DocumentRequestHandler 实现提供绝对路径,例如 res://myImage.pngfile: //myImage.png

You need to explain how you loaded the HTML, images are loaded relatively to the base URL so you need to define the base URL when creating the HTML (its implicitly detected when loading via URL).

If you created the HTML via setHTML(String) then you need to give absolute paths depending on your DocumentRequestHandler implementation e.g. res://myImage.png or file://myImage.png .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文