List of usage examples for android.graphics Bitmap compress
@WorkerThread public boolean compress(CompressFormat format, int quality, OutputStream stream)
From source file:Main.java
public static byte[] toByteArray(final Bitmap bitmap) { final ByteArrayOutputStream output = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, output); bitmap.recycle();/*from w ww . j a va 2 s .c o m*/ return output.toByteArray(); }
From source file:Main.java
public static byte[] compressBitmap(Bitmap bitmap) { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); if (bitmap.compress(Bitmap.CompressFormat.JPEG, 80, byteStream)) { try {//from w ww .ja v a 2 s .com byteStream.flush(); byteStream.close(); } catch (IOException ex) { ex.printStackTrace(); } } return byteStream.toByteArray(); }
From source file:Main.java
public static byte[] formatByteArray(Bitmap bitmap) { byte[] data;/*from w ww .j a v a 2 s . c o m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); data = baos.toByteArray(); return data; }
From source file:Main.java
public static byte[] getByteArrayFromBitmap(final Bitmap bitmap, int quality) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, out); return out.toByteArray(); }
From source file:Main.java
public static String getBase64FromBitmap(Bitmap bitmap, int bitmapQuality) { ByteArrayOutputStream bStream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, bitmapQuality, bStream); byte[] bytes = bStream.toByteArray(); return Base64.encodeToString(bytes, Base64.DEFAULT); }
From source file:Main.java
public static byte[] BitmapToBytes(Bitmap paramBitmap) { ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(); paramBitmap.compress(Bitmap.CompressFormat.PNG, 100, localByteArrayOutputStream); return localByteArrayOutputStream.toByteArray(); }
From source file:Main.java
public static byte[] getBitmapBytes(Bitmap paramBitmap) { ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(); paramBitmap.compress(Bitmap.CompressFormat.PNG, 100, localByteArrayOutputStream); return localByteArrayOutputStream.toByteArray(); }
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;/* w w w .ja v a 2 s . c o 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 void saveToFile(String filename, Bitmap bmp) { try {/*from w w w. jav a 2s.c om*/ FileOutputStream out = new FileOutputStream(filename); bmp.compress(CompressFormat.PNG, 100, out); out.flush(); out.close(); } catch (Exception e) { Log.d("Exception", e.getMessage()); } }
From source file:Main.java
public static String getImagePath(Context context, Bitmap inImage) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = Images.Media.insertImage(context.getContentResolver(), inImage, "Title", null); return path;//from w w w . jav a 2 s .c o m }