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

/**
 * function encrypt the string and return the result
 * @param stringToEncrypt the string against which the encryption to be performed
 * @return the encrypted String/*from w w w .  j a va  2s.  c  om*/
 */
public static final String encrypt(String stringToEncrypt) {
    try {
        byte[] data = stringToEncrypt.getBytes("UTF-8");
        String base64 = Base64.encodeToString(data, Base64.DEFAULT);
        return base64;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return stringToEncrypt;

    //        try {
    //            Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
    //            Cipher cipher = Cipher.getInstance("AES");
    //            cipher.init(Cipher.ENCRYPT_MODE, aesKey);
    //            byte[] encrypted = cipher.doFinal(stringToEncrypt.getBytes());
    //            return new String(encrypted);
    //        }catch (Exception e){
    //
    //        }
    //        return null;
}

From source file:Main.java

public static String getBase64FromBitmap(Bitmap bitmap, int bitmapQuality) {
    ByteArrayOutputStream bStream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, bitmapQuality, bStream);
    byte[] bytes = bStream.toByteArray();
    return Base64.encodeToString(bytes, Base64.DEFAULT);
}

From source file:Main.java

public static String bitmaptoString(Bitmap bitmap) {
    String string = null;/*  w w  w. j  ava 2  s . co m*/
    ByteArrayOutputStream bStream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 50, bStream);
    byte[] bytes = bStream.toByteArray();
    string = Base64.encodeToString(bytes, Base64.DEFAULT);
    return string;
}

From source file:Main.java

public static String encodeToBase64(Bitmap image) {
    Bitmap immagex = image;//from   w  w  w  .jav  a 2s  . c o  m
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
    return imageEncoded;
}

From source file:Main.java

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

From source file:Main.java

public static String bmpToString(Bitmap bitmap) {
    String bmpStr = "";
    try {/*w  ww.jav a2  s. c  o m*/
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
        byte[] bts = outputStream.toByteArray();
        bmpStr = Base64.encodeToString(bts, Base64.DEFAULT);
    } catch (Exception e) {
        // TODO: handle exception
    }
    return bmpStr;
}

From source file:Main.java

public static String encodeTobase64(Bitmap image) {
    Bitmap immagex = image;/*from w w  w .j  av  a 2  s  .  c  om*/
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
    return imageEncoded;
}

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, 0);
}

From source file:Main.java

public static String Base64Pic(String path) throws Exception {
    Bitmap bm = getSmallBitmap(path, 300, 300);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    return Base64.encodeToString(b, Base64.DEFAULT);
}

From source file:Main.java

/**
 * generate base64 from bitmap image/*from  ww  w.j  a  v  a2  s .co  m*/
 * @param mBitmap bitmap image
 * @return base64 string
 */
public static String ImageToBase64(Bitmap mBitmap) {
    ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
    mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos1);
    byte[] b1 = baos1.toByteArray();
    return Base64.encodeToString(b1, Base64.DEFAULT);
}