title: Android convert image from gallery into base64 result in OutOfMemory Exception
body: <p>I would like to load image from gallery and then convert it into base64.</p>
  
  <p>This does not sound so difficult. So i dod it this way:</p>
  
  <p>first of all open gallery and choose picture:</p>
  
  <pre><code>picteureBtn.setOnClickListener(new View.OnClickListener() {
              private Uri imageUri;
  
              public void onClick(View view) {
                  Intent i = new Intent(
                          Intent.ACTION_PICK,
                          android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  
                  startActivityForResult(i, RESULT_LOAD_IMAGE);
  
              }
          });
  </code></pre>
  
  <p>second onActivityResult:</p>
  
  <pre><code>@Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
          if (requestCode == RESULT_LOAD_IMAGE &amp;&amp; resultCode == RESULT_OK &amp;&amp; null != data) {
              Uri selectedImage = data.getData();
              String[] filePathColumn = { MediaStore.Images.Media.DATA };
  
              Cursor cursor = getContentResolver().query(selectedImage,
                      filePathColumn, null, null, null);
              cursor.moveToFirst();
  
              int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
              picturePath = cursor.getString(columnIndex);
              cursor.close();
  
  
          }
  
  
      }
  </code></pre>
  
  <p>and for the end way i want to decode my <code>image</code> which is at <code>picutrePath</code></p>
  
  <pre><code>                String b64;
                  StringEntity se;
                  String entityContents="";
                  if (!picturePath.equals("")){
                      Bitmap bm = BitmapFactory.decodeFile(picturePath);
                      ByteArrayOutputStream baos = new ByteArrayOutputStream();  
                      bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
  
                      byte[] b = baos.toByteArray(); 
                      b64=Base64.encodeToString(b, Base64.DEFAULT);
                  }
  </code></pre>
  
  <p>Unfortunatly I get :</p>
  
  <pre><code>06-24 16:38:14.296: E/AndroidRuntime(3538): FATAL EXCEPTION: main
  06-24 16:38:14.296: E/AndroidRuntime(3538): java.lang.OutOfMemoryError
  06-24 16:38:14.296: E/AndroidRuntime(3538):     at java.io.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:122)
  </code></pre>
  
  <p>Can anyone point me where I am doing mistake?</p>