List of usage examples for android.graphics Bitmap compress
@WorkerThread public boolean compress(CompressFormat format, int quality, OutputStream stream)
From source file:Main.java
/** * generate base64 from bitmap image/*from w w w .jav a2 s. c om*/ * @param mBitmap bitmap image * @return base64 string */ public static String ImageToBase64(Bitmap mBitmap) { ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos1); byte[] b1 = baos1.toByteArray(); return Base64.encodeToString(b1, Base64.DEFAULT); }
From source file:Main.java
public static byte[] getBitmapByte(Bitmap bitmap) { ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); try {/*from ww w .j a va 2 s . c o m*/ out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } return out.toByteArray(); }
From source file:Main.java
public static byte[] convertToByteArray(Bitmap bmp) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 80, stream); byte[] byteArray = stream.toByteArray(); try {/*from www. j a v a 2 s . c o m*/ stream.close(); } catch (IOException e) { e.printStackTrace(); } return byteArray; }
From source file:Main.java
public static InputStream Bitmap2InputStream(Bitmap bm, int quality) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, quality, baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is;//w w w . j a v a2 s .c o m }
From source file:Main.java
public static byte[] bitmapToByteArray(Bitmap bitmap) { ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); return out.toByteArray(); }
From source file:Main.java
public static String bitmapToString(Bitmap bm, int rate) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, rate, baos); byte[] b = baos.toByteArray(); return Base64.encodeToString(b, Base64.DEFAULT); }
From source file:Main.java
public static String bmpToStrBase64(Bitmap bitmap) { Bitmap bm = bitmap; ByteArrayOutputStream stream = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 80, stream); //bm is the bitmap object byte[] b = stream.toByteArray(); String strBase64 = Base64.encodeToString(b, 0); return strBase64; }
From source file:Main.java
public static byte[] getBitmapByte(Bitmap bitmap) { ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); try {/* ww w . j av a 2 s .c om*/ out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } return out.toByteArray(); }
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 String convertToBase64(Bitmap bmp) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 80, stream); byte[] byteArray = stream.toByteArray(); try {//from w w w.ja va 2 s . c o m stream.close(); } catch (IOException e) { e.printStackTrace(); } return Base64.encodeToString(byteArray, Base64.DEFAULT); }