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[] bitmapToByteArray(Bitmap $bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); $bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] byteArray = stream.toByteArray(); return byteArray; }
From source file:Main.java
/** * Converts a bitmap to a byte array/*from w ww. ja v a 2 s . c om*/ * @param bitmap * @return */ public static byte[] getImageBytes(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream); return stream.toByteArray(); }
From source file:Main.java
public static String getImageAsString(Bitmap bmp) { ByteArrayOutputStream bYtE = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, bYtE); byte[] byteArray = bYtE.toByteArray(); String image = Base64.encodeToString(byteArray, Base64.DEFAULT); bmp.recycle();// www . j av a 2s . co m Log.d("Converted TO : ", image); return image; }
From source file:Main.java
public static byte[] toByteArray(Bitmap bitmap) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); return outputStream.toByteArray(); }
From source file:Main.java
public static String bitmapToBase64String(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 80, baos); byte[] bitmapArray = baos.toByteArray(); String encodeString = Base64.encodeToString(bitmapArray, Base64.DEFAULT); return encodeString; }
From source file:Main.java
public static byte[] toBytes(Bitmap bitmap) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, PNG_SAVE_QUALITY, outputStream); return outputStream.toByteArray(); }
From source file:Main.java
public static InputStream bitmap2InputStream(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is;//from w ww .j a va 2 s . com }
From source file:Main.java
public static byte[] decodeBitmapToBytes(Bitmap bitmap) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 100, outputStream); return outputStream.toByteArray(); }
From source file:Main.java
public static byte[] bitmap2Bytes(Bitmap bm, int quality) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, quality, baos); return baos.toByteArray(); }
From source file:Main.java
/** * Compress the bitmap to a PNG and return its {@link ByteArrayInputStream} * /*from w w w . ja v a2 s.c o m*/ * @param bitmap The {@link Bitmap} to compress * @return The {@link ByteArrayInputStream} */ public static ByteArrayInputStream toPNGInputStream(Bitmap bitmap) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes); return new ByteArrayInputStream(bytes.toByteArray()); }