List of usage examples for java.io ByteArrayOutputStream ByteArrayOutputStream
public ByteArrayOutputStream()
From source file:Main.java
public static byte[] bitmap2Bytes(Bitmap bitmap, CompressFormat format) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(format, 100, baos);//from ww w . j a va 2 s . com return baos.toByteArray(); }
From source file:Main.java
public static String encodeBitmap(Bitmap bitmap, Bitmap.CompressFormat compressFormat) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(compressFormat, 100, baos); byte[] bytes = baos.toByteArray(); byte[] encodedImage = Base64.encode(bytes, Base64.DEFAULT); return new String(encodedImage); }
From source file:Main.java
static byte[] serialize(Serializable obj) throws IOException { ByteArrayOutputStream b = new ByteArrayOutputStream(); ObjectOutputStream o = new ObjectOutputStream(b); o.writeObject(obj);/*w w w .j a va 2 s .co m*/ return b.toByteArray(); }
From source file:Main.java
public static byte[] getFileDataFromBitmap(Context context, Bitmap bitmap) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 0, byteArrayOutputStream); return byteArrayOutputStream.toByteArray(); }
From source file:Main.java
public static byte[] readStream(InputStream is) throws Exception { byte[] bytes = new byte[1024]; int leng;//from w w w . ja va 2 s .c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); while ((leng = is.read(bytes)) != -1) { baos.write(bytes, 0, leng); } return baos.toByteArray(); }
From source file:Main.java
public static final byte[] getImageByteArray(Bitmap bi) { byte[] data;// w ww .j av a2s . c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); data = baos.toByteArray(); return data; }
From source file:Main.java
public static Bitmap codec(Bitmap src, Bitmap.CompressFormat format, int quality) { ByteArrayOutputStream os = new ByteArrayOutputStream(); src.compress(format, quality, os);/*from w w w .j a va 2 s.c o m*/ byte[] array = os.toByteArray(); return BitmapFactory.decodeByteArray(array, 0, array.length); }
From source file:Main.java
public static Bitmap codec(Bitmap src, Bitmap.CompressFormat format, int quality) { ByteArrayOutputStream os = new ByteArrayOutputStream(); src.compress(format, quality, os);// w ww .j a v a2 s . c o m byte[] array = os.toByteArray(); return BitmapFactory.decodeByteArray(array, 0, array.length); }
From source file:Main.java
/** * bitmap2Bytes/*w w w .j a v a 2 s . c om*/ * * @param bm * @return */ public static byte[] bitmap2Bytes(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); }
From source file:Main.java
public static String bitmapToBase64String(Bitmap bm) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 80, bos); byte[] b = bos.toByteArray(); return Base64.encodeToString(b, Base64.DEFAULT); }