Encode Bitmap to a base64 string - Android android.graphics

Android examples for android.graphics:Bitmap Create

Description

Encode Bitmap to a base64 string

Demo Code

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;
import android.util.Log;
import java.io.ByteArrayOutputStream;

public class Main{

    public static final String getStringFromBitmap(Bitmap bitmap) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        return Base64.encodeToString(stream.toByteArray(), Base64.DEFAULT);
    }//  w  w  w  . java  2 s .  co m

}

Related Tutorials