title: How to create bitmap from sdcard images in android?
body: <p>I need to create a bitmap from sdcard images so after getting uri of image i am getting byte data by opening inputStream as follows</p>
  
  <pre><code>public byte[] getBytesFromFile(InputStream is)
  {
      byte[] data = null;
      ByteArrayOutputStream buffer=null;
      try
      {
          buffer = new ByteArrayOutputStream();
  
          int nRead;
          data = new byte[16384];
          while ((nRead = is.read(data, 0, data.length)) != -1)
          {
              buffer.write(data, 0, nRead);
          }
  
          buffer.flush();
  
          return buffer.toByteArray();
      } catch (IOException e)
      {
          return null;
      }
      finally
      {
          if(data!=null)
              data = null;
          if(is!=null)
              try {
                  is.close();
              } catch (Exception e)
              {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              if(buffer!=null)
              {
                  try {
                      buffer.close();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
                  buffer = null;
              }
              System.gc();
      }
  </code></pre>
  
  <p>after this i am just creating bitmap of that data by following code</p>
  
  <pre><code>byte[] data = getBytesFromFile(is);
  Bitmap bm= BitmapFactory.decodeByteArray(data, 0, data.length);
  </code></pre>
  
  <p>but it gives me outofmemory error. many peoples guide me to check for memory leakages but, this is the first step in my app., i mean thru intent filter i start my app from gallery menu option "share" which invokes my app with the image uri..
  plz guide me guys if i am wrong... and also this exception comes on the devices which have high resolution images(size excceds 1MB), but any how it should create Bitmap...</p>