【问题标题】:BlackBerry embedded browser: image display using HTML黑莓嵌入式浏览器:使用 HTML 显示图像
【发布时间】:2012-01-27 11:17:12
【问题描述】:

我正在开发一个使用嵌入式浏览器来显示 html 内容的 BlackBerry 应用程序。
在 Torch 上测试应用程序我意识到浏览器只显示项目嵌入的图像,而我在访问存储在可移动 SD 卡或内部文件系统上的图像资源文件时遇到问题。
在 Curve 上运行的同一应用程序可以正确显示所有图像。
下面是一段代码:

    browser = new BrowserField();

    Strimg img_1 = "file:///store/home/user/yellow.png";
    Strimg img_2 = "file:///SDCard/green.png";
    Strimg img_3 = "file:///local/images/red.png";

String  imgTag_1 = "<img src=\"" + img_1 + "\">"; // Stored on file system - Not displayed by Torch
String  imgTag_2 = "<img src=\"" + img_2 + "\">"; // Stored on SDCard - Not displayed by Torch
String  imgTag_3 = "<img src=\"" + img_3 + "\">"; // Embedded image

String browserContent = "<html>" + imgTag_1 + imgTag_2 + imgTag_3 + "</html>";

byte[] contentBytes;        
try {
    contentBytes = browserContent.getBytes("UTF-8");
    browser.displayContent(contentBytes, "text/html; charset=UTF-8", "http://mysite.com");
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    browser.displayContent(browserContent, "http://mysite.com");
}

aVerticalManager.add(browser);


我将 JRE 5 用于 Curve 和 Torch。 使用 FileConnector 访问文件工作正常。

关于如何在 Torch 和 Curve 上显示图像有什么建议吗? 谢谢

【问题讨论】:

    标签: html blackberry browser image


    【解决方案1】:

    解决了!
    以下代码描述了我是如何做到的:

    browser = new BrowserField();    
    String img_1 = "file:///store/home/user/yellow.png"; // File Sistem
    
    byte[] byt_1    = MyUtilClass.readBytesFromFile(img_1);
    char[] base64_1 = MyUtilClass.Base64.encode(byt_1);
    
    // Sample of generating HTML: <html><img src="data:image/bmp;base64,Axcfhhòjbnesohokòbw...."></img></html>
    String imgTag_1 = "<html><img src= \"data:image/bmp;base64,"+ String.valueOf(base64_1) + "\" ></img></html>";
    
    byte[] contentBytes;       
    
    contentBytes = imgTag_1.getBytes("UTF-8");
    
    // Inject HTML in browser
    browser.displayContent(contentBytes, "text/html; charset=UTF-8", "http://mysite.com");
    


    所以,这在 Torch 上效果很好,但我在 Curve 上的表现很差。我将根据设备类型对行为进行专门化处理。

    if ( Curve == true ) {
    // Use: <img src=file:///store/home/user/yellow.png>
    } else  {
    // Use: <img src="data:image/bmp;base64,Axcfhhòjbnesohokòbw...."></img>
    }
    


    我知道这是一种解决方法,但它确实有效!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-28
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      • 2010-09-29
      • 1970-01-01
      • 2017-04-19
      相关资源
      最近更新 更多