Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.ByteArrayOutputStream;

import android.graphics.Bitmap;

import android.util.Base64;

public class Main {
    /**
     * This method converts bitmap to base64 string.
     * 
     * @param bitmap
     * @return base64EncodedImage
     */
    public static String encodeTobase64(Bitmap bitmap) {
        // TODO Auto-generated method stub
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] b = baos.toByteArray();
        return Base64.encodeToString(b, Base64.DEFAULT);
    }
}