LWUIT HtmlComponent 渲染本地图像
我想渲染我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要解释如何加载 HTML,图像是相对于基本 URL 加载的,因此您需要在创建 HTML 时定义基本 URL(通过 URL 加载时会隐式检测到)。
如果您通过
setHTML(String)
创建 HTML,那么您需要根据您的 DocumentRequestHandler 实现提供绝对路径,例如res://myImage.png
或file: //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
orfile://myImage.png
.