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 String bitmapToString(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    return Base64.encodeToString(b, Base64.DEFAULT);
}

From source file:Main.java

private static byte[] readBitmap(Bitmap bmp) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 60, baos);
    try {/*from ww w . j  a v  a2s .c o m*/
        baos.flush();
        baos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return baos.toByteArray();
}

From source file:Main.java

public static final 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;// w  w w . java2  s. c om
}

From source file:Main.java

public static String getBitmapStrBase64(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] bytes = baos.toByteArray();
    return Base64.encodeToString(bytes, 0);
}

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[] readStream(InputStream inputStream) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int len = 0;// w ww  .  j a va2 s.  com
    while ((len = inputStream.read(buffer)) != -1) {
        outputStream.write(buffer, 0, len);
    }
    outputStream.close();
    inputStream.close();
    return outputStream.toByteArray();
}

From source file:Main.java

public static byte[] getBitmapByte(Bitmap bitmap) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
    try {//from   www . ja va2 s .c o m
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return out.toByteArray();
}

From source file:Main.java

public static byte[] bitmapToBytes(Bitmap bitmap, Bitmap.CompressFormat format) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    if (format == null) {
        format = Bitmap.CompressFormat.PNG;
    }//from  w  w w.ja v  a 2s .  c om

    bitmap.compress(format, 100, stream);
    byte[] byteArray = stream.toByteArray();
    return byteArray;
}

From source file:Main.java

public static byte[] concatenateTwoByteArrays(byte a[], byte b[]) throws IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    outputStream.write(a);/*  w  ww.j a  va 2  s  . c  o  m*/
    outputStream.write(b);
    return outputStream.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();
}