0

我正在尝试使用 BrowserField 渲染图像。但是我遇到了图像显示这样的问题(渲染不良):

在此处输入图像描述

图像比屏幕大,我使用此代码加载它:

public ImagesScreen(String urlImage,int number)
{
super(VERTICAL_SCROLL | HORIZONTAL_SCROLL);

BrowserFieldConfig config = new BrowserFieldConfig();
config.setProperty(BrowserFieldConfig.USER_SCALABLE, Boolean.TRUE);
browserField = new BrowserField(config);

scale = initscale = Float.valueOf(formatNumber(((float) 1 / (1703 / Display.getWidth())), 8, "."));

add(browserField);
Log.info("scala " + scale);//" + scale + "
String htmlContent = "<html><meta name='viewport' content='width = device-width,maximum-scale=10.0, minimum-scale=0.001, initial-scale=" + scale + ", user-scalable=yes' /><body style='margin: 0px;padding: 0px;float: left;'>";
for (int i = 1; i <= number;i++)
{
    htmlContent += "<img width='1703' alt='' src='" + urlImage + "000"+i+".png"+"'/>";
}
System.out.println(urlImage);
htmlContent += "</body></html>";
browserField.displayContent(htmlContent, "http://localhost");
UiApplication.getUiApplication().pushScreen(this);
};

如果我让比例为 1 ,它仍然有这个问题。谢谢阅读 :) 。

4

1 回答 1

0

让 BrowserField 完成所有工作:

    String imgFile = "..."; // here the image file pathname        
    String style   = "..."; // here the css style

    String imgTag = "<div class=\"image\"> <img src="
           + imgFile
           + "></img></div><div class=\"clear\"></div>";

    String browserContent = "<html><style>" + style + "</style>" + imgTag + "</html>";

    byte[] contentBytes;        

    try {
        contentBytes = browserContent.getBytes("UTF-8");
        browser.displayContent(contentBytes, "text/html; charset=UTF-8", "");
    } catch (UnsupportedEncodingException e) {
        ...
    }
于 2012-05-18T12:10:55.823 回答