List of usage examples for java.io ByteArrayOutputStream toByteArray
public synchronized byte[] toByteArray()
From source file:Main.java
private static InputStream bitmapToStream(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 100, baos); InputStream sbs = new ByteArrayInputStream(baos.toByteArray()); return sbs;//from w w w . ja v a 2 s . c o m }
From source file:Main.java
public static byte[] bitmap2Bytes(Bitmap bm) { if (bm == null || bm.isRecycled()) { return null; }/*from w ww . j a v a 2 s. c om*/ byte[] bytes; ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); bytes = baos.toByteArray(); try { baos.flush(); baos.close(); } catch (IOException e) { e.printStackTrace(); } return bytes; }
From source file:Main.java
/** * convert (encode) image to string//from ww w . j a va 2 s . c om * **/ public static String encodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality) { ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream(); image.compress(compressFormat, quality, byteArrayOS); return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT); }
From source file:Main.java
public static byte[] bitmapToBytes(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 InputStream getInputStream(Bitmap bitmap) { ByteArrayOutputStream bStream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, 100, bStream); return new ByteArrayInputStream(bStream.toByteArray()); }
From source file:Main.java
public static byte[] bitampToByteArray(Bitmap bitmap) { byte[] array = null; try {/*from w w w. ja v a2 s . com*/ if (null != bitmap) { ByteArrayOutputStream os = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); array = os.toByteArray(); os.close(); } } catch (IOException e) { e.printStackTrace(); } return array; }
From source file:Main.java
public static byte[] bitmap2Bytes(Bitmap bitmap) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); return byteArrayOutputStream.toByteArray(); }
From source file:Main.java
public static void saveImage(Context context, String fileName, Bitmap bitmap, int quality) throws IOException { if (bitmap == null || fileName == null || context == null) return;/*from www .ja v a 2 s . c o m*/ FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream); byte[] bytes = stream.toByteArray(); fos.write(bytes); fos.close(); }
From source file:Main.java
public static InputStream convertToInputStream(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] imageInByte = stream.toByteArray(); System.out.println("........length......" + imageInByte); ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte); return bis;/* www .j ava 2 s . c om*/ }
From source file:Main.java
public static byte[] objectToByte(Object obj) throws Exception { ObjectOutputStream oos = null; try {/* w w w .j av a 2s . c o m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(obj); return bos.toByteArray(); } finally { if (oos != null) oos.close(); } }