Android Bitmap to String Convert base64Bitmap(File file)

Here you can find the source of base64Bitmap(File file)

Description

base Bitmap

Declaration

public static final String base64Bitmap(File file) 

Method Source Code

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.ExifInterface;
import android.media.ThumbnailUtils;
import android.util.Base64;
import android.view.View;

public class Main{
    public static final String base64Bitmap(Bitmap bitmap) {
        ByteArrayOutputStream out = null;
        try {//from   ww  w.j a  va 2 s. c  o m
            out = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
            out.flush();
            out.close();
            byte[] imgBytes = out.toByteArray();
            return Base64.encodeToString(imgBytes, Base64.DEFAULT);
        } catch (Exception e) {
            LogUtility.d(e);
        } finally {
            StreamUtility.closeStream(out);
        }
        return "";
    }
    public static final String base64Bitmap(File file) {
        return base64Bitmap(BitmapFactory.decodeFile(file.getPath()));
    }
}

Related

  1. bitmap2Base64(Bitmap bitmap, int bitmapQuality)
  2. convertBase64ToBitmap(String data)