Image expected but null value returned
<p>I am trying to load an image file from my gallery, but am getting null instead of the expected image. Here is the code I am using:</p>

<pre><code>public static Bitmap decodeSampledBitmapFromStreem(InputStream is,
        int reqWidth, int reqHeight) {
    Bitmap b = null;
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(is, null, options);
    options.inSampleSize = calculateInSampleSize(options, reqWidth,
            reqHeight);
    options.inJustDecodeBounds = false;
    b = BitmapFactory.decodeStream(is, null, options);
    return b;
}
public static int calculateInSampleSize(BitmapFactory.Options options,
        int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height &gt; reqHeight || width &gt; reqWidth) {
        if (width &gt; height) {
            inSampleSize = Math.round((float) height / (float) reqHeight);
        } else {
            inSampleSize = Math.round((float) width / (float) reqWidth);
        }
    }
    return inSampleSize;
}
</code></pre>

<p>Can you see any problem in my code? Why am I getting null? </p>

<p>Please note that my code works fine for small images if i comment the 6th line, however I am getting error for larger images as per my error Log:</p>

<pre><code>05-17 11:37:46.277: E/AndroidRuntime(9224): FATAL EXCEPTION: AsyncTask #3
05-17 11:37:46.277: E/AndroidRuntime(9224): java.lang.RuntimeException: An error occured while executing doInBackground()
05-17 11:37:46.277: E/AndroidRuntime(9224):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at java.lang.Thread.run(Thread.java:1019)
05-17 11:37:46.277: E/AndroidRuntime(9224): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
05-17 11:37:46.277: E/AndroidRuntime(9224):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at com.giftcard.GiftCard.decodeSampledBitmapFromStreem(GiftCard.java:454)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at com.giftcard.GiftCard$MyBitmapDecoder.doInBackground(GiftCard.java:500)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at com.giftcard.GiftCard$MyBitmapDecoder.doInBackground(GiftCard.java:1)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
05-17 11:37:46.277: E/AndroidRuntime(9224):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
05-17 11:37:46.277: E/AndroidRuntime(9224):     ... 4 more
05-17 11:37:49.387: I/Process(9224): Sending signal. PID: 9224 SIG: 9
</code></pre>
