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

/**
 * convert bitmap to byte[]//from w ww.j a va 2s .c o m
 * 
 * @param bitmap
 * @return byte[]
 */
public static byte[] bitmap2Bytes(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    return baos.toByteArray();
}

From source file:Main.java

/**
 * bitmap to bytes[]/* w w  w .ja  v  a 2  s  . c o m*/
 */
private static byte[] bitmap2Bytes(Bitmap bitmap) {
    if (bitmap == null) {
        return null;
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    return baos.toByteArray();
}

From source file:Main.java

public static byte[] bitmap2Byte(Bitmap bitmap) {
    if (bitmap == null) {
        return null;
    }//w w  w.j  a  v  a2  s .c om
    int size = bitmap.getWidth() * bitmap.getHeight();
    ByteArrayOutputStream baos = new ByteArrayOutputStream(size);
    bitmap.compress(CompressFormat.JPEG, 100, baos);
    return baos.toByteArray();
}

From source file:Main.java

public static String BitmapToBase64PNG(Bitmap bmp) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 40, baos);
    byte[] data = baos.toByteArray();
    return Base64.encodeToString(data, Base64.DEFAULT);
}

From source file:Main.java

public static String bitMapToString(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] b = baos.toByteArray();
    String temp = Base64.encodeToString(b, Base64.DEFAULT);
    return temp;/*from   w  w  w  . j a  va  2 s  .  c om*/
}

From source file:Main.java

public static byte[] bitmapToByte(Bitmap bitmap) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] yy = baos.toByteArray();
    return yy;/*ww  w.jav  a  2 s. co m*/
}

From source file:Main.java

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

From source file:Main.java

public static String encodeToJPEGbase64(Bitmap image) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    image.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 byte[] convertToBytes(Bitmap bitmap, CompressFormat format, int quality) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(format, quality, stream);
    byte[] data = stream.toByteArray();
    try {// www .  j  a v a 2s . c o  m
        stream.close();
    } catch (Exception e) {
        // nothing
    }
    return data;
}

From source file:Main.java

/**
 * Converts bitmap to byte array//from   w w w. j a  v  a2 s  .co  m
 *
 * @param bitmap
 * @return
 */
public static byte[] getBytes(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
    return stream.toByteArray();
}