Android bitmap and Data Stream Conversion, androidbitmap
Bitmap aa = BitmapFactory. decodeResource (getResources (), R. drawable. ic_launcher );
InputStream input = datastream (aa); // converts bitmap to stream
Bitmap bitmap = transformation (input); // converts a stream to a bitmap
Public InputStream datastream (Bitmap bm ){
ByteArrayOutputStream stream = new ByteArrayOutputStream ();
Bm. compress (Bitmap. CompressFormat. PNG, 100, stream );
ByteArrayInputStream is = new ByteArrayInputStream (stream. toByteArray ());
Return is;
}
Public Bitmap transformation (InputStream input ){
If (input! = Null ){
Int len =-1;
Byte [] temp = new byte [4*1024];
ByteArrayBuffer buffer = new ByteArrayBuffer (2x1024*1024 );
Try {
While (len = input. read (temp ))! =-1 ){
Buffer. append (temp, 0, len );
}
Bitmap bmp = BitmapFactory. decodeByteArray (buffer. buffer (), 0, buffer. length (); // convert the stream to bitmap
} Catch (IOException e ){
E. printStackTrace ();
}
}
Return bmp;
}