Encode large size image to Base64 String in android
Encode Image
public String BitMapToString(Bitmap bitmap){ ByteArrayOutputStream baos=new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG,100, 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(); bitmap.compress(Bitmap.CompressFormat.JPEG,50, baos); b=baos.toByteArray(); temp=Base64.encodeToString(b, Base64.DEFAULT); Log.e("EWN", "Out of memory error catched"); } return temp; }
Happy Coding.