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

    File imageFile = null;/*  ww  w.  j  a  v a  2 s.  c  om*/
    try {
        imageFile = File.createTempFile("tempImage" + System.currentTimeMillis(), ".png");
    } catch (IOException e) {
        e.printStackTrace();
    }

    FileOutputStream fstream = null;
    try {
        fstream = new FileOutputStream(imageFile);
        BufferedOutputStream bStream = new BufferedOutputStream(fstream);
        bStream.write(byteArray);
        if (bStream != null) {
            bStream.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return imageFile;

}