Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.graphics.Bitmap;
import android.util.Base64;
import java.io.ByteArrayOutputStream;

public class Main {
    public static String bmpToStrBase64(Bitmap bitmap) {

        Bitmap bm = bitmap;
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.JPEG, 80, stream); //bm is the bitmap object
        byte[] b = stream.toByteArray();
        String strBase64 = Base64.encodeToString(b, 0);

        return strBase64;
    }
}