Base64 encode Bitmap To - Android android.graphics

Android examples for android.graphics:Bitmap Load Save

Description

Base64 encode Bitmap To

Demo Code

import java.io.ByteArrayOutputStream;

import android.graphics.Bitmap;
import android.util.Base64;

public class Main {

  public static String encodeBitmapToBase64(Bitmap bitmap) {

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
    byte[] byteArray = byteArrayOutputStream.toByteArray();
    return Base64.encodeToString(byteArray, Base64.DEFAULT);

  }/*from   ww w . ja v a  2 s . c o  m*/

}

Related Tutorials