黑莓嵌入式浏览器:使用HTML图像显示 [英] BlackBerry embedded browser: image display using HTML

查看:151
本文介绍了黑莓嵌入式浏览器:使用HTML图像显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发,它使用嵌入式浏览器显示HTML内容的黑莓应用程序。结果
在火炬测试应用程序,我意识到,只有项目嵌入图像是由浏览器中显示,虽然我已经有了访问存储可移动SD卡或内部文件系统的图像上的资源文件的问题。结果
曲线上运行同一应用程序正确显示所有图像。结果
这里是code的片段:

I'm developing a BlackBerry app which uses an embedded browser to display html content.
Testing application on Torch I've realized that only project embedded images are displayed by browser, while I've got problems accessing image resource files stored on removable SD card or internal file system.
The same application running on Curve displays correctly all the images.
Here is a fragment of code:

    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无论是曲线和火炬。
使用FileConnector来访问文件工作正常。


I'm using JRE 5 both for Curve and Torch. Using FileConnector to accessing file works fine.

如何既对火炬和曲线显示图像上有什么建议?
由于搜索结果

Any suggestions on how to display images both on Torch and Curve? Thanks

推荐答案

解决了!结果
以下的code描述如何我做到了:结果

Solved!
Hereafter the code describing how I did it:

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");

结果
所以,这个工作在火炬很好,但我对曲线表现不佳。我会根据设备类型的专门的行为。结果


So, this works fine on Torch, but I have poor performances on Curve. I'll specialize the behaviour depending on device type.

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

结果
我知道这是一种解决方法,但它的作品!


I know that is a workaround, but it works!

这篇关于黑莓嵌入式浏览器:使用HTML图像显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆