开发者

LWUIT HtmlComponent render local image

开发者 https://www.devze.com 2023-04-04 14:12 出处:网络
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

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开发者_StackOverflow中文版>

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


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 .

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号