BitmapFactory.decodeStream returning null when options are set
<p>I'm having issues with <code>BitmapFactory.decodeStream(inputStream)</code>. When using it without options, it will return an image. But when I use it with options as in <code>.decodeStream(inputStream, null, options)</code> it never returns Bitmaps.</p>

<p>What I'm trying to do is to downsample a Bitmap before I actually load it to save memory.
I've read some good guides, but none using <code>.decodeStream</code>.</p>

<ul>
<li><p><em><a href="http://groups.google.com/group/android-developers/browse_thread/thread/1e9d19c3adf1a768/afef1c8341a63ad2?lnk=gst&amp;q=samuh#afef1c8341a63ad2">Handling large Bitmaps</a></em></p></li>
<li><p><a href="http://nornalbion.Scom/blog/?p=143">And here</a></p></li>
<li><p><em><a href="http://kfb-android.blogspot.com/2009/04/image-processing-in-android.html">Image Processing in Android</a></em></p></li>
</ul>

<p><strong>WORKS JUST FINE</strong></p>

<pre><code>URL url = new URL(sUrl);
HttpURLConnection connection  = (HttpURLConnection) url.openConnection();

InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is, null, options);
</code></pre>

<p><strong>DOESN'T WORK</strong></p>

<pre><code>InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is, null, options);

InputStream is = connection.getInputStream();

Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

BitmapFactory.decodeStream(is, null, options);

Boolean scaleByHeight = Math.abs(options.outHeight - TARGET_HEIGHT) &gt;= Math.abs(options.outWidth - TARGET_WIDTH);

if (options.outHeight * options.outWidth * 2 &gt;= 200*100*2){
    // Load, scaling to smallest power of 2 that'll get it &lt;= desired dimensions
    double sampleSize = scaleByHeight
    ? options.outHeight / TARGET_HEIGHT
    : options.outWidth / TARGET_WIDTH;
    options.inSampleSize =
        (int)Math.pow(2d, Math.floor(
        Math.log(sampleSize)/Math.log(2d)));
}

// Do the actual decoding
options.inJustDecodeBounds = false;
Bitmap img = BitmapFactory.decodeStream(is, null, options);
</code></pre>
