encode Bitmap to Base64 String - Android android.graphics

Android examples for android.graphics:Bitmap Load Save

Description

encode Bitmap to 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 encodeTobase64(Bitmap image) {
        Bitmap immagex = image;//  ww  w. jav a  2s.  c om
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] b = baos.toByteArray();
        String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);

        Log.e("encodeTobase64", imageEncoded);
        return imageEncoded;
    }

}

Related Tutorials