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[] getBitmapAsByteArray(Bitmap bitmap) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 0, outputStream);
    return outputStream.toByteArray();
}

From source file:Main.java

public static String encodeToBase64(Bitmap image) {
    Bitmap immagex = image;//  www . j a va2 s  . c  o  m
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    immagex.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[] bitmapToBytes(Bitmap bm) {
    byte[] bytes = null;
    if (bm != null) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
        bytes = baos.toByteArray();
    }/* w  w w. j a v a 2  s .  c  o m*/
    return bytes;
}

From source file:Main.java

/**
 * convert Bitmap to byte array/*from ww w. ja  v  a 2s  . c  om*/
 * @param bitmap
 * @return
 */
public static byte[] bitmapToByte(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[] toByteArray(InputStream input) throws IOException {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    copy(input, output);/*from  w w w.j  av  a 2 s .  c om*/
    return output.toByteArray();
}

From source file:Main.java

public static String bitmaptoString(Bitmap bitmap) {
    String string = null;/*from  w w  w . j  av a2 s.c  o m*/
    ByteArrayOutputStream bStream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 50, bStream);
    byte[] bytes = bStream.toByteArray();
    string = Base64.encodeToString(bytes, Base64.DEFAULT);
    return string;
}

From source file:Main.java

public static String encodeTobase64(Bitmap image) {
    Bitmap immagex = image;/*  www.  ja v a  2 s.  c  om*/
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    immagex.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[] getBitmapToBytes(Bitmap bitmap) {
    if (bitmap != null) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        return baos.toByteArray();
    }//www . ja  v a  2  s . c o  m
    return null;
}

From source file:Main.java

public static String openAsBase64(String imgPath) {
    Bitmap photo = BitmapFactory.decodeFile(imgPath);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    photo.compress(Bitmap.CompressFormat.JPEG, 85, baos);
    byte[] b = baos.toByteArray();
    photo.recycle();//from  w w w  .  j  a va 2  s. c o  m
    return Base64.encodeToString(b, Base64.DEFAULT);

}

From source file:Main.java

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