List of usage examples for java.io ByteArrayOutputStream toByteArray
public synchronized byte[] toByteArray()
From source file:Main.java
public static String BitmapToBase64(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); return Base64.encodeToString(imageBytes, Base64.DEFAULT); }
From source file:Main.java
public static byte[] getImageByte(Bitmap bitmap) { // imageView.setDrawingCacheEnabled(true); // Bitmap bitMap = imageView.getDrawingCache(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] imageBytes = baos.toByteArray(); return imageBytes; }
From source file:Main.java
public static byte[] getBytes(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] byteArray = stream.toByteArray(); return byteArray; }
From source file:Main.java
/** * convert Bitmap to InputStream/*from w w w . j a v a 2 s . c o m*/ */ public static InputStream bitmapToStream(Bitmap bitmap, Bitmap.CompressFormat compressFormat) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(compressFormat, 100, bos); return new ByteArrayInputStream(bos.toByteArray()); }
From source file:Main.java
public static InputStream getBitmapPngStream(Bitmap theBitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); theBitmap.compress(Bitmap.CompressFormat.PNG, 95, baos); byte[] data = baos.toByteArray(); return new ByteArrayInputStream(data); }
From source file:Main.java
public static byte[] getBitmap2Bytes(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); return byteArray; }
From source file:Main.java
public static byte[] getImageBytes(Bitmap bmp) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return imageBytes; }
From source file:Main.java
public static InputStream getBitmapJpegStream(Bitmap theBitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); theBitmap.compress(Bitmap.CompressFormat.JPEG, 95, baos); byte[] data = baos.toByteArray(); return new ByteArrayInputStream(data); }
From source file:Main.java
/** * generate base64 from bitmap image// w ww . j a v a 2 s . c o m * @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[] compress(Bitmap bitmap, int persentage) { if (bitmap == null) return new byte[0]; if (persentage <= 0) persentage = 0;/*w w w . j a v a2s. co m*/ else if (persentage > 100) persentage = 100; ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, persentage, baos); return baos.toByteArray(); }