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 {
    public static String encodeBitmap(Bitmap bitmap, Bitmap.CompressFormat compressFormat) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(compressFormat, 100, baos);
        byte[] bytes = baos.toByteArray();
        byte[] encodedImage = Base64.encode(bytes, Base64.DEFAULT);
        return new String(encodedImage);
    }
}