Here you can find the source of base64Bitmap(Bitmap bitmap)
public static final String base64Bitmap(Bitmap bitmap)
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileDescriptor; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.media.ExifInterface; import android.media.ThumbnailUtils; import android.util.Base64; import android.view.View; public class Main{ public static final String base64Bitmap(Bitmap bitmap) { ByteArrayOutputStream out = null; try {//from w ww. j a va2 s . co m out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); byte[] imgBytes = out.toByteArray(); return Base64.encodeToString(imgBytes, Base64.DEFAULT); } catch (Exception e) { LogUtility.d(e); } finally { StreamUtility.closeStream(out); } return ""; } public static final String base64Bitmap(File file) { return base64Bitmap(BitmapFactory.decodeFile(file.getPath())); } }