Note that there are some explanatory texts on larger screens.

plurals
  1. POBitmapFactory.decodeStream returns null without exception
    primarykey
    data
    text
    <p>I try to load a remote image from a server and thanks to a lot of code examples on stackoverflow I have a solution which works in 2 out of 3 images. I don't really know what the problem is with the third picture and sometimes when letting the code run in the debugger the picture is loading. Also if I load the problem picture first the other two pictures are sometimes not loaded.</p> <p>Here is the code:</p> <pre><code>public static Drawable getPictureFromURL(Context ctx, String url, final int REQUIRED_SIZE) throws NullPointerException { //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); int scale = 1; if (o.outWidth &gt; REQUIRED_SIZE) { scale = (int) Math.pow(2, (int) Math.round(Math.log(REQUIRED_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } Log.i(Prototype.TAG, "scale: "+scale); //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; Bitmap bmp; try { bmp = BitmapFactory.decodeStream((InputStream) Tools.fetch(url), null, o2); if(bmp!=null) return new BitmapDrawable(ctx.getResources(), bmp); else return null; } catch (Exception e) { Log.e(Prototype.TAG, "Exception while decoding stream", e); return null; } } </code></pre> <p>During debugging I found out that o.outWidth is -1 which indicates an error, but no Exception is thrown, so I can't really tell what went wrong. The InputStream always returned a valid value, and I know that the picture exists on the server.</p> <p>Best wishes, Daniel</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload