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[] BitmapToByteArray(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] byteArray = stream.toByteArray();

    return byteArray;
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static byte[] Bitmap2Bytes(Bitmap bm) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (bm != null) {

        bm.compress(Bitmap.CompressFormat.PNG, 100, baos);

    }/*from  w  w  w.j av  a  2s.c  o  m*/

    return baos.toByteArray();
}

From source file:Main.java

public static byte[] bitmapToByteArray(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 byte[] bitmap2Bytes(Bitmap bm, int quality) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, quality, baos);
    return baos.toByteArray();
}

From source file:Main.java

public static byte[] serialize(Object obj) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ObjectOutputStream os;/*from w w  w  .  java  2 s.c  o m*/
    try {
        os = new ObjectOutputStream(out);
        os.writeObject(obj);
        return out.toByteArray();
    } catch (Exception e) {

        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static byte[] getByteArrayFromBitmap(Bitmap bmp) {

    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 0, bytes);

    return bytes.toByteArray();
}

From source file:Main.java

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

From source file:Main.java

public static byte[] toByteArray(Object obj) {
    byte[] returnBytes = null;
    ByteArrayOutputStream byteArrayOutStream = new ByteArrayOutputStream();
    ObjectOutput objectOut = null;
    try {//from   w w w . j a  va  2s .c o  m
        objectOut = new ObjectOutputStream(byteArrayOutStream);
        objectOut.writeObject(obj);
        returnBytes = byteArrayOutStream.toByteArray();
    } catch (java.io.IOException ioe) {
        return null;
    } finally {
        try {
            objectOut.close();
            byteArrayOutStream.close();
        } catch (java.io.IOException ioe) {

        }
    }
    return returnBytes;
}