jacorso
jacorso

Reputation: 31

Webview not displaying certian Images all versions below KitKat (API19)

I am using a webview to display an image from the web. For some reason it is displaying most images but there are a few that just display blank. Image that works: http://asset.treering.com/P65/27176195.0_- Image that doesnt:http://asset.treering.com/P00/26683156.0_-

Here is the code I am using to display:

WebView wv = new WebView(context);
        if (url != null)
        {
            wv.setVerticalScrollBarEnabled(false);
            wv.setHorizontalScrollBarEnabled(false);

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {

                 // only for gingerbread and newer versions
                String data = "<html><body ><img id=\"resizeImage\" src=\"" + url + "_-" + "\" width=\"100%\" alt=\"\" align=\"middle\" /></body></html>";
                wv.loadData(data, "text/html; charset=UTF-8", null);
            }
            else
            {
                this.setPadding(scale5, scale5, scale5, scale5);
                wv.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
                wv.loadUrl(url + "_-"); 
            }
            addView(wv,new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
        }

Upvotes: 1

Views: 409

Answers (1)

jacorso
jacorso

Reputation: 31

Solution:
Turns out the images not displaying were encoded with 32 bit depth. The android webview prior to android 4.4 is unable to display JPEG images with anything higher than 24 bit depth. You either need to change the image to PNG (which android suports 32 bit depth) or export the image as 24 bit depth.

Upvotes: 2

Related Questions