Java tutorial
//package com.java2s; // Use of this source code is governed by a BSD-style license that can be import android.graphics.Bitmap; import android.util.Base64; import java.io.ByteArrayOutputStream; public class Main { /** * Compresses a bitmap into a PNG and converts into a Base64 encoded string. * The encoded string can be decoded using {@link decodeBitmapFromString(String)}. * @param bitmap The Bitmap to compress and encode. * @return the String encoding the Bitmap. */ public static String encodeBitmapAsString(Bitmap bitmap) { if (bitmap == null) return ""; ByteArrayOutputStream output = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, output); return Base64.encodeToString(output.toByteArray(), Base64.DEFAULT); } }