Example usage for android.util Base64 encodeToString

List of usage examples for android.util Base64 encodeToString

Introduction

In this page you can find the example usage for android.util Base64 encodeToString.

Prototype

public static String encodeToString(byte[] input, int flags) 

Source Link

Document

Base64-encode the given data and return a newly allocated String with the result.

Usage

From source file:Main.java

public static String bitmapToBase64String(Bitmap bm) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
    byte[] b = bos.toByteArray();
    return Base64.encodeToString(b, Base64.DEFAULT);
}

From source file:Main.java

public static String getImageAsString(Bitmap bmp) {
    ByteArrayOutputStream bYtE = new ByteArrayOutputStream();

    bmp.compress(Bitmap.CompressFormat.JPEG, 100, bYtE);
    byte[] byteArray = bYtE.toByteArray();
    String image = Base64.encodeToString(byteArray, Base64.DEFAULT);
    bmp.recycle();/*from   w  w w.  jav a  2  s.  c o m*/
    Log.d("Converted TO : ", image);
    return image;
}

From source file:Main.java

public static String bitmapToString(Bitmap bm, int rate) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, rate, baos);
    byte[] b = baos.toByteArray();
    return Base64.encodeToString(b, Base64.DEFAULT);
}

From source file:Main.java

public static String base64Encode(String s) {
    byte[] data = new byte[0];
    try {/*w w w  .j a v a  2s .c o m*/
        data = s.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } finally {
        return Base64.encodeToString(data, Base64.NO_WRAP);
    }
}

From source file:Main.java

public static String encodeBase64File(String path) throws Exception {
    File file = new File(path);
    FileInputStream inputFile = new FileInputStream(file);
    byte[] buffer = new byte[(int) file.length()];
    inputFile.read(buffer);//from w w w . j a v  a 2s  . c  o m
    inputFile.close();
    return Base64.encodeToString(buffer, Base64.DEFAULT);
}

From source file:Main.java

public static String bitmapToBase64(Bitmap bitmap) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes);
    byte[] byteArr = bytes.toByteArray();
    return Base64.encodeToString(byteArr, Base64.DEFAULT);
}

From source file:Main.java

public static String bitmapToBase64(Bitmap bmp) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 75, byteArrayOutputStream);
    byte[] imgBytes = byteArrayOutputStream.toByteArray();

    return Base64.encodeToString(imgBytes, Base64.DEFAULT);
}

From source file:Main.java

public static String bitMapToString(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] b = baos.toByteArray();
    String temp = Base64.encodeToString(b, Base64.DEFAULT);
    return temp;/*  w w w. j a v a2 s.  co m*/
}

From source file:Main.java

public static String toBase64(Bitmap bitmap) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
    byte[] byteArray = byteArrayOutputStream.toByteArray();

    return Base64.encodeToString(byteArray, Base64.DEFAULT);
}

From source file:Main.java

public static String bitmapToBase64(Bitmap bitmap) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
    byte[] byteArray = byteArrayOutputStream.toByteArray();
    return Base64.encodeToString(byteArray, Base64.DEFAULT);
}