List of usage examples for java.io ByteArrayOutputStream ByteArrayOutputStream
public ByteArrayOutputStream()
From source file:Main.java
static private byte[] readBytesFromStream(InputStream input) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead;/*from ww w .j a v a 2 s.co m*/ byte[] data = new byte[16384]; while ((nRead = input.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); input.close(); return buffer.toByteArray(); }
From source file:Main.java
public static String bitmapToBase64(Bitmap bitmap) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes); byte[] byteArr = bytes.toByteArray(); return Base64.encodeToString(byteArr, Base64.DEFAULT); }
From source file:Main.java
public static String bitmapChangeString(Bitmap bitmap) { if (bitmap != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); String str = new String(Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT)); return str; }/*w ww . j a v a 2 s .c o m*/ return null; }
From source file:Main.java
public static byte[] bitmapToByteArray(Bitmap bitmap) { if (bitmap == null) { return null; }/*ww w . ja v a 2s.c o m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); }
From source file:Main.java
public static InputStream Bitmap2InputStream(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is;/*from ww w . ja v a 2 s . com*/ }
From source file:Main.java
public static String inToString(InputStream in) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] data = new byte[BUFFER_SIZE]; int count = -1; while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) outStream.write(data, 0, count); data = null;/*w w w . j a va2 s . c o m*/ return new String(outStream.toByteArray()); }
From source file:Main.java
public static byte[] bitmapToBytes(Bitmap bitmap) { if (bitmap == null) { return null; }// w w w .ja va 2 s .c o m final ByteArrayOutputStream os = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); return os.toByteArray(); }
From source file:Main.java
public static InputStream Bitmap2InputStream(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is;/* ww w . java 2 s.c o m*/ }
From source file:Main.java
public static String bitmapToString(Bitmap bitmap) { String bitmapString = null;/* ww w. java 2s.com*/ ByteArrayOutputStream bStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, bStream); byte[] bytes = bStream.toByteArray(); bitmapString = Base64.encodeToString(bytes, Base64.DEFAULT); return bitmapString; }
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 av a 2 s . co m }