Android Bitmap to String Convert bitmap2Base64(Bitmap bitmap, int bitmapQuality)

Here you can find the source of bitmap2Base64(Bitmap bitmap, int bitmapQuality)

Description

bitmap Base

License

Open Source License

Declaration

public static String bitmap2Base64(Bitmap bitmap, int bitmapQuality) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;
import android.graphics.Bitmap;

import android.util.Base64;

public class Main {
    public static String bitmap2Base64(Bitmap bitmap, int bitmapQuality) {
        String string = null;//from www. j  av  a  2s.  c o  m
        byte[] bytes = bitmapToBytes(bitmap);
        string = Base64.encodeToString(bytes, Base64.DEFAULT);
        return string;
    }

    public static byte[] bitmapToBytes(Bitmap bm) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
        return baos.toByteArray();
    }
}

Related

  1. base64Bitmap(File file)
  2. convertBase64ToBitmap(String data)