Convert bitmap To Base64 String - Android Graphics

Android examples for Graphics:Bitmap String

Description

Convert bitmap To Base64 String

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.util.Base64;

import java.io.ByteArrayOutputStream;

public class Main {
    public static String bitmapToBase64(Bitmap bitmap) {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes);
        byte[] byteArr = bytes.toByteArray();
        return Base64.encodeToString(byteArr, Base64.DEFAULT);
    }/*from  ww w.j  a va 2 s .  co  m*/
}

Related Tutorials