title: Large images to base64
body: <p>I search for this over forum but I not find good solution. I found very similar themes, but not helping.</p>
  
  <p>I have problem when i try to encode large image files to base64.. I try to use lower quality but i have problem with large files again.. i use :</p>
  
  <pre><code>public String BitMapToString(Bitmap bitmap,String Ext){
      ByteArrayOutputStream baos=new  ByteArrayOutputStream();
      if(Ext.equals("png")){
          bitmap.compress(Bitmap.CompressFormat.PNG, 50, baos); 
      }else{
          bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos); 
      }
      byte [] b=baos.toByteArray();
          String temp = null;
          try {
              System.gc();
              temp = Base64.encodeToString(b, Base64.DEFAULT);
          } catch (Exception e) {
              e.printStackTrace();
          } catch (OutOfMemoryError e) {
              baos = new ByteArrayOutputStream();
              if (Ext.equals("png")) {
                  bitmap.compress(Bitmap.CompressFormat.PNG, 20, baos); 
              } else {
                  bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);   
              }
              b = baos.toByteArray();
              temp = Base64.encodeToString(b, Base64.DEFAULT);
              Log.e("EWN", "Out of memory error catched");
          }
          return temp;        
  }
  </code></pre>
  
  <p>Now this work for litle files excelent ( lets say &lt;1 mb) when i use quality lower than 100 (in this example 50 or 20) i get ok with litle large file(maybe 3 mb ) but this is not good solution because i still have problem with size 10 mb for example...Program just break.. </p>
  
  <p>I was think to convert in chunks ,but this not work for me... </p>
  
  <p>Thank you for answer.</p>