Why decodeStream returns null when options.inSampleSize is derived rather than set
<p>Ok Someone help me figure this out.  I am using the Bitmap.options as recommended by other threads and android tutorials to figure out the inSample size. The problem that the following code is resulting in null bitmap instead of scaled bitmap</p>

<pre><code>    private int determineCorrectScale(InputStream imageStream){

        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(imageStream, null, o);

        // The new size we want to scale to
        final int REQUIRED_SIZE = 100;

        // Find the correct scale value. It should be the power of 2.
        int scale = 1;
        while (o.outWidth / scale / 2 &gt;= REQUIRED_SIZE &amp;&amp; o.outHeight / scale / 2 &gt;= REQUIRED_SIZE) {
            scale *= 2;
        }

        return scale;

    }
    private String saveScaledBitmapToPhone(Uri imagUri){

        InputStream imageStream;
        try {
            imageStream = getContentResolver().openInputStream(imagUri);

            int scale= determineCorrectScale(imageStream);

            BitmapFactory.Options options=new BitmapFactory.Options();
            options.inSampleSize = scale;

            Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream, null, options );

.
.
.
.
        } catch (Exception e) {
            return imagUri.toString(); //default

        }
}
</code></pre>

<p>The problem that yourSelectedImage is null. However if I comment out the line</p>

<pre><code>  int scale= determineCorrectScale(imageStream);
</code></pre>

<p>and set the insampleSize to 8 or 16 or any other fixed manual number then everything works fine. Can any one explain this behaviour or how to fix it?  My feeling says it is due to creating two Options objects of static class but that's just a guess. I still can't fix it :(
PLEASE HELP</p>
