Example usage for java.io ByteArrayOutputStream toByteArray

List of usage examples for java.io ByteArrayOutputStream toByteArray

Introduction

In this page you can find the example usage for java.io ByteArrayOutputStream toByteArray.

Prototype

public synchronized byte[] toByteArray() 

Source Link

Document

Creates a newly allocated byte array.

Usage

From source file:Main.java

private static String getStringImage(Bitmap bmp) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
    return encodedImage;
}

From source file:Main.java

public static byte[] bitmapToByte(String path) {
    File file = new File(path);
    if (!file.exists()) {
        return null;
    }//from ww w .java 2  s . c o  m
    Bitmap bitmap = BitmapFactory.decodeFile(path);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
    return bos.toByteArray();
}

From source file:Main.java

public static byte[] toBytes(Bitmap bitmap) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
    return outputStream.toByteArray();
}

From source file:de.burlov.crypt.CryptUtils.java

static public byte[] decrypt(byte[] ciphertext, byte[] key) throws IOException {
    CryptInputStream in = new CryptInputStream(new ByteArrayInputStream(ciphertext), new SerpentEngine(), key);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    IOUtils.copy(in, bout);//  w  w w. j a  v a  2s. co  m
    return bout.toByteArray();
}

From source file:Main.java

public static byte[] decodeBytes(Bitmap bm) {
    if (bm == null) {
        return null;
    }/*from  www  .  j  a v  a  2s .com*/
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
        return baos.toByteArray();
    } catch (OutOfMemoryError e) {
        return null;
    }
}

From source file:Main.java

/**
 * This method converts bitmap to base64 string.
 * // w w w  .j  a  v a2  s  .  co m
 * @param bitmap
 * @return base64EncodedImage
 */
public static String encodeTobase64(Bitmap bitmap) {
    // TODO Auto-generated method stub
    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 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 bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
    return encodedImage;
}

From source file:Main.java

public static byte[] toByteArray(Bitmap bitmap) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
    return outputStream.toByteArray();
}

From source file:Main.java

public static byte[] convertBitmapToByteArray(Bitmap bitmap) {
    if (bitmap == null) {
        return null;
    } else {/*from  w  w  w .j  a  v  a 2 s .  c  om*/
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        return stream.toByteArray();
    }
}