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 BitmapToByte(Bitmap bitmap) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 50, byteArrayOutputStream);
    return new String(Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT));
}

From source file:Main.java

static void setBasicAuthentication(HttpURLConnection conn, URL url) {
    String userInfo = url.getUserInfo();
    if (userInfo != null && userInfo.length() > 0) {
        String authString = Base64.encodeToString(userInfo.getBytes(), Base64.DEFAULT);
        conn.setRequestProperty("Authorization", "Basic " + authString);
    }/*w  w w.j a v a  2  s . co m*/
}

From source file:Main.java

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

From source file:Main.java

public static String BitmapToBase64PNG(Bitmap bmp) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 40, baos);
    byte[] data = baos.toByteArray();
    return Base64.encodeToString(data, Base64.DEFAULT);
}

From source file:Main.java

/**
 * Generate HTTP Basic Authorization Header
 * //from w ww .ja v  a  2 s .  c o  m
 * @param username username
 * @param password password
 * @return Generated header
 */
public static String getPasswordDigest(String username, String password) {
    String authString = username + ":" + password;
    return Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP);
}

From source file:Main.java

public static String bitmapToString(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    return Base64.encodeToString(b, Base64.DEFAULT);
}

From source file:Main.java

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

From source file:Main.java

public static String BitmapToBase64(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    return Base64.encodeToString(imageBytes, Base64.DEFAULT);
}

From source file:Main.java

public static final 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;//from   w w w  .j a  v a  2s  . co m
}

From source file:Main.java

public static String BitMapToString(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] arr = baos.toByteArray();
    String result = Base64.encodeToString(arr, Base64.DEFAULT);
    return result;
}