BlackBerry embedded browser: image display using HTML

前端 未结 1 1431
囚心锁ツ
囚心锁ツ 2020-12-18 13:37

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 ar

相关标签:
1条回答
  • 2020-12-18 14:26

    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!

    0 讨论(0)
提交回复
热议问题