List of usage examples for java.io ByteArrayOutputStream ByteArrayOutputStream
public ByteArrayOutputStream()
From source file:Main.java
private static byte[] getBytes(InputStream is) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] b = new byte[2048]; int len = 0;//from w w w . j ava2s. c om try { while ((len = is.read(b, 0, 2048)) != -1) { baos.write(b, 0, len); baos.flush(); } } catch (IOException e) { e.printStackTrace(); } byte[] bytes = baos.toByteArray(); return bytes; }
From source file:Main.java
/** * convert Bitmap to byte array/*from ww w . j ava2 s. co m*/ */ public static byte[] bitmapToByte(Bitmap b) { ByteArrayOutputStream o = new ByteArrayOutputStream(); b.compress(Bitmap.CompressFormat.PNG, 100, o); return o.toByteArray(); }
From source file:Main.java
public static byte[] bitmapToByteArray(Bitmap $bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); $bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] byteArray = stream.toByteArray(); return byteArray; }
From source file:Main.java
public static byte[] getBytes(Bitmap bitmap) { ByteArrayOutputStream baops = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 0, baops); return baops.toByteArray(); }
From source file:Main.java
public static byte[] getBytes(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 0, stream); return stream.toByteArray(); }
From source file:Main.java
public static byte[] readStream(InputStream in) throws IOException { byte[] ret = null; if (in != null) { ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] buf = new byte[128]; int len;/*from w ww . j a v a2s . c o m*/ while (true) { len = in.read(buf); if (len == -1) { break; } bout.write(buf, 0, len); } buf = null; ret = bout.toByteArray(); } return ret; }
From source file:Main.java
public static byte[] bitmap2Bytes(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(CompressFormat.PNG, 100, baos); return baos.toByteArray(); }
From source file:Main.java
public static byte[] encodeToByteArray(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); }
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(); }/*from w w w . j a v a2 s. c o m*/ return null; }
From source file:Main.java
public static String bitmapToBase64String(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 80, baos); byte[] bitmapArray = baos.toByteArray(); String encodeString = Base64.encodeToString(bitmapArray, Base64.DEFAULT); return encodeString; }