List of usage examples for java.io ByteArrayOutputStream toByteArray
public synchronized byte[] toByteArray()
From source file:Main.java
public static InputStream getInputStreamFromBitmap(Bitmap bitmap) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); final byte[] bitmapdata = out.toByteArray(); final ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata); return bs;//from w ww . ja va 2s . c om }
From source file:Main.java
public static String convertBitmapToString(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos); byte[] b = baos.toByteArray(); String temp = null;/* ww w. jav a2 s.co m*/ try { System.gc(); temp = Base64.encodeToString(b, Base64.DEFAULT); } catch (Exception e) { e.printStackTrace(); } catch (OutOfMemoryError e) { baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos); b = baos.toByteArray(); temp = Base64.encodeToString(b, Base64.DEFAULT); } return temp; }
From source file:Main.java
public static byte[] compressBitmap(Bitmap bitmap) { ByteArrayOutputStream os = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, COMPRESS_JPEG_QUALITY, os); return os.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:com.surfs.storage.common.util.HttpUtils.java
private static String readResponse(InputStream is) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); IOUtils.copy(is, os);/*from w w w . j a v a2s .c om*/ return new String(os.toByteArray(), "UTF-8"); }
From source file:Main.java
public static InputStream bitmap2Ins(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(CompressFormat.JPEG, 100, baos); InputStream sbs = new ByteArrayInputStream(baos.toByteArray()); return sbs;/*from w w w.j a v a 2s . c o m*/ }
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;//w ww . j av a2 s. co m FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, quality, stream); byte[] bytes = stream.toByteArray(); fos.write(bytes); fos.close(); }
From source file:Main.java
/** * This method writes the XML into a nicely formatted string. * /*from www . j a v a 2 s . c o m*/ * @param eRoot The root element. * @return The nicely formatted string. */ public static String writePretty(Element eRoot) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writePretty(eRoot, baos); return new String(baos.toByteArray()); }
From source file:br.edu.ifpb.utils.PhotoUtils.java
public static byte[] getByteImage(BufferedImage imagem) throws IOException { if (imagem == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(imagem, "jpg", baos); byte[] bytes = baos.toByteArray(); return bytes; }
From source file:Main.java
/** * Convert a bitmap to a byte array/*from w ww.j a va 2 s .c o m*/ * @param path the path to the picture on the phone * @return the image in a byte array */ public static byte[] picToByte(Bitmap bitmap) { if (bitmap == null) { return null; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 10, baos); byte[] ba = baos.toByteArray(); try { baos.close(); } catch (IOException e) { Log.e("Error", "Error closing output stream" + e.getMessage()); return null; } return ba; }