Example usage for java.io ByteArrayOutputStream ByteArrayOutputStream

List of usage examples for java.io ByteArrayOutputStream ByteArrayOutputStream

Introduction

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

Prototype

public ByteArrayOutputStream() 

Source Link

Document

Creates a new ByteArrayOutputStream .

Usage

From source file:Main.java

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

    return byteArray;
}

From source file:Main.java

public static synchronized byte[] bitmapToByteArray(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    return stream.toByteArray();
}

From source file:Main.java

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

From source file:Main.java

public static byte[] Bitmap2Bytes(Bitmap bm, int ratio) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, ratio, baos);
    //add/*from   www .j a v a2s  .  c  o m*/
    if (bm != null && !bm.isRecycled()) {
        bm.recycle();
        bm = null;
    }
    return baos.toByteArray();
}

From source file:Main.java

public static byte[] toByteArray(final Bitmap bitmap) {

    final ByteArrayOutputStream output = new ByteArrayOutputStream();

    bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);

    bitmap.recycle();//from www  .  j  a v  a 2  s  .c o  m

    return output.toByteArray();
}

From source file:Main.java

public static <T> byte[] serializeToByteArray(T object) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {/*w ww . ja  v a 2s .c om*/

        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(object);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return baos.toByteArray();
}

From source file:Main.java

public static String bitmapToBase64(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object   
    byte[] b = baos.toByteArray();
    return Base64.encodeToString(b, Base64.DEFAULT);
}

From source file:Main.java

public static byte[] BitmapToBytes(Bitmap paramBitmap) {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    paramBitmap.compress(Bitmap.CompressFormat.PNG, 100, localByteArrayOutputStream);
    return localByteArrayOutputStream.toByteArray();
}

From source file:Main.java

public static byte[] getBitmapBytes(Bitmap paramBitmap) {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    paramBitmap.compress(Bitmap.CompressFormat.PNG, 100, localByteArrayOutputStream);
    return localByteArrayOutputStream.toByteArray();
}

From source file:Main.java

public static byte[] formatByteArray(Bitmap bitmap) {
    byte[] data;/*from  ww  w  . ja  v a  2  s.com*/
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    data = baos.toByteArray();
    return data;
}