List of usage examples for android.graphics Bitmap compress
@WorkerThread public boolean compress(CompressFormat format, int quality, OutputStream stream)
From source file:Main.java
private static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) { ByteArrayOutputStream output = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, output); if (needRecycle) { bmp.recycle();/*w w w . j av a2s. c o m*/ } byte[] result = output.toByteArray(); try { output.close(); } catch (Exception e) { } return result; }
From source file:Main.java
public static byte[] bmp2byteArray(Bitmap bitmap, Bitmap.CompressFormat format, int compressVal) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(format, compressVal, baos); return baos.toByteArray(); }
From source file:Main.java
private static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) { ByteArrayOutputStream output = new ByteArrayOutputStream(); bmp.compress(CompressFormat.PNG, 100, output); if (needRecycle) { bmp.recycle();/*from www . ja v a2 s .c om*/ } byte[] result = output.toByteArray(); try { output.close(); } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:Main.java
/** * This method converts bitmap to base64 string. * /*from w w w . jav a 2 s .c o m*/ * @param bitmap * @return base64EncodedImage */ public static String encodeTobase64(Bitmap bitmap) { // TODO Auto-generated method stub ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] b = baos.toByteArray(); return Base64.encodeToString(b, Base64.DEFAULT); }
From source file:Main.java
public static String Base64Pic(String path) throws Exception { Bitmap bm = getSmallBitmap(path, 300, 300); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] b = baos.toByteArray(); return Base64.encodeToString(b, Base64.DEFAULT); }
From source file:Main.java
public static byte[] bitmap2Bytes(Bitmap bitmap) { ByteArrayOutputStream baos;/*from w w w.ja v a 2s. c o m*/ try { baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] b = baos.toByteArray(); baos.flush(); baos.close(); return b; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) { ByteArrayOutputStream output = new ByteArrayOutputStream(); bmp.compress(CompressFormat.PNG, 100, output); if (needRecycle) { bmp.recycle();//from w ww . j av a2s .c o m } byte[] result = output.toByteArray(); try { output.close(); } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static byte[] bitmap2ByteArray(final Bitmap bmp, final boolean needRecycle) { ByteArrayOutputStream output = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, output); if (needRecycle) { bmp.recycle();// ww w . ja va 2s. c om } byte[] result = output.toByteArray(); try { output.close(); } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static boolean compress(Bitmap bitmap, File outFile) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 35, baos); try {/*from www.j a v a 2 s .c om*/ FileOutputStream fileOutputStream = new FileOutputStream(outFile); fileOutputStream.write(baos.toByteArray()); fileOutputStream.close(); } catch (Exception e) { return false; } return true; }
From source file:Main.java
public static byte[] getBitmap2Bytes(Bitmap photo) { if (photo == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); photo.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); }