title: loading large bitmaps efficiently android
body: <p>I'm trying to load large bitmap.</p>
  
  <p>I read this:
  <a href="http://developer.android.com/training/displaying-bitmaps/load-bitmap.html" rel="nofollow">http://developer.android.com/training/displaying-bitmaps/load-bitmap.html</a></p>
  
  <p>and I try to create the same method from string</p>
  
  <pre><code>public static Bitmap decodeSampleBitmapFromStream(InputStream is, int reqWidth, int reqHeight){
        // First decode with inJustDecodeBounds=true to check dimensions
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(is,null,options);
  
        // Calculate inSampleSize
        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
  
        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
        return  BitmapFactory.decodeStream(is,null,options);
  }
  </code></pre>
  
  <p>I'm sure the inputStream is correct because in a previous version I was directly loading the bitmaps</p>
  
  <p>using decodeSampleBitmapFromStream I always have a null return</p>
  
  <p>Thanks</p>
  
  <p>Edit</p>
  
  <p>I try to add this after the inputStream use</p>
  
  <pre><code>try {
      is.mark(1 &lt;&lt; 24);
      // also try is.mark(0);
      is.reset();
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  </code></pre>
  
  <p>I have this error</p>
  
  <pre><code>06-18 09:55:31.831: W/System.err(16460): java.io.IOException
  06-18 09:55:31.831: W/System.err(16460):    at java.io.InputStream.reset(InputStream.java:221)
  06-18 09:55:31.831: W/System.err(16460):    at ant.fileExplorer.FileExplorerAdapter.decodeSampleBitmapFromStream(FileExplorerAdapter.java:124)
  06-18 09:55:31.831: W/System.err(16460):    at ant.fileExplorer.FileExplorerAdapter.getView(FileExplorerAdapter.java:56)
  06-18 09:55:31.831: W/System.err(16460):    at android.widget.AbsListView.obtainView(AbsListView.java:1430)
  06-18 09:55:31.831: W/System.err(16460):    at android.widget.ListView.makeAndAddView(ListView.java:1793)
  06-18 09:55:31.831: W/System.err(16460):    at android.widget.ListView.fillDown(ListView.java:670)
  06-18 09:55:31.831: W/System.err(16460):    at android.widget.ListView.fillFromTop(ListView.java:727)
  06-18 09:55:31.831: W/System.err(16460):    at android.widget.ListView.layoutChildren(ListView.java:1646)
  06-18 09:55:31.831: W/System.err(16460):    at android.widget.AbsListView.onLayout(AbsListView.java:1260)
  06-18 09:55:31.841: W/System.err(16460):    at android.view.View.layout(View.java:7277)
  06-18 09:55:31.841: W/System.err(16460):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
  06-18 09:55:31.841: W/System.err(16460):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
  06-18 09:55:31.841: W/System.err(16460):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
  06-18 09:55:31.841: W/System.err(16460):    at android.view.View.layout(View.java:7277)
  06-18 09:55:31.841: W/System.err(16460):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
  06-18 09:55:31.841: W/System.err(16460):    at android.view.View.layout(View.java:7277)
  06-18 09:55:31.841: W/System.err(16460):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
  06-18 09:55:31.841: W/System.err(16460):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
  06-18 09:55:31.841: W/System.err(16460):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
  06-18 09:55:31.841: W/System.err(16460):    at android.view.View.layout(View.java:7277)
  06-18 09:55:31.841: W/System.err(16460):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
  06-18 09:55:31.841: W/System.err(16460):    at android.view.View.layout(View.java:7277)
  06-18 09:55:31.841: W/System.err(16460):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1203)
  06-18 09:55:31.841: W/System.err(16460):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1957)
  06-18 09:55:31.841: W/System.err(16460):    at android.os.Handler.dispatchMessage(Handler.java:99)
  06-18 09:55:31.841: W/System.err(16460):    at android.os.Looper.loop(Looper.java:150)
  06-18 09:55:31.841: W/System.err(16460):    at android.app.ActivityThread.main(ActivityThread.java:4277)
  06-18 09:55:31.841: W/System.err(16460):    at java.lang.reflect.Method.invokeNative(Native Method)
  06-18 09:55:31.851: W/System.err(16460):    at java.lang.reflect.Method.invoke(Method.java:507)
  06-18 09:55:31.851: W/System.err(16460):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  06-18 09:55:31.851: W/System.err(16460):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  06-18 09:55:31.851: W/System.err(16460):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>