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

public static byte[] Bitmap2Bytes(Bitmap bm, Bitmap.CompressFormat format) {
    if (bm == null) {
        return null;
    }/*  w ww  . j  ava 2  s  .c  o  m*/
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(format, 100, baos);
    return baos.toByteArray();
}

From source file:Main.java

public static byte[] serializerBytes(Object xmlObj) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(xmlObj.getClass());
    Marshaller marshaller = context.createMarshaller();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    marshaller.marshal(xmlObj, baos);//from  w ww  .j a va 2s  . co m
    return baos.toByteArray();
}

From source file:Main.java

public static byte[] bitmapToByte(Bitmap bitmap, Bitmap.CompressFormat fmt) {
    if (bitmap == null)
        return null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(fmt, 100, baos);/*from w  w  w.  j a  v a  2  s. co  m*/
    return baos.toByteArray();
}

From source file:Main.java

public static byte[] bitmapToByteArray(Bitmap b) {
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    b.compress(Bitmap.CompressFormat.PNG, 50, bs);
    return bs.toByteArray();
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static byte[] compress(Bitmap bitmap, int quality, Bitmap.CompressFormat format) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(format, quality, baos);
    return baos.toByteArray();
}

From source file:Main.java

public static Bitmap codec(Bitmap src, Bitmap.CompressFormat format, int quality) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    src.compress(format, quality, os);//ww w. j a  v a2s. co  m
    byte[] array = os.toByteArray();
    return BitmapFactory.decodeByteArray(array, 0, array.length);
}

From source file:Main.java

public static byte[] changeBitmapToByte(Bitmap bm) {
    ByteArrayOutputStream baOut = new ByteArrayOutputStream();
    bm.compress(CompressFormat.PNG, 100, baOut);
    return baOut.toByteArray();
}

From source file:Main.java

public static byte[] Bitmap2Bytes(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(CompressFormat.PNG, 100, baos);
    return baos.toByteArray();
}