Java tutorial
//package com.java2s; //License from project: Open Source License import android.annotation.SuppressLint; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.util.Base64; import java.io.ByteArrayOutputStream; public class Main { @SuppressLint("NewApi") public static String getBitmapStrBase64(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 100, baos); byte[] bytes = baos.toByteArray(); String data = Base64.encodeToString(bytes, 0, bytes.length, Base64.DEFAULT); if (bitmap != null) { bitmap.recycle(); bitmap = null; } return data; } }