Example usage for android.graphics Bitmap compress

List of usage examples for android.graphics Bitmap compress

Introduction

In this page you can find the example usage for android.graphics Bitmap compress.

Prototype

@WorkerThread
public boolean compress(CompressFormat format, int quality, OutputStream stream) 

Source Link

Document

Write a compressed version of the bitmap to the specified outputstream.

Usage

From source file:Main.java

public static byte[] convertBitmapToByteArray(Bitmap bmp) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] byteArray = stream.toByteArray();
    return byteArray;
}

From source file:Main.java

public static String encodeToBase64(Bitmap image) {
    Bitmap immagex = image;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
    return imageEncoded;
}

From source file:Main.java

public static byte[] bitmapToByteArray(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] array = stream.toByteArray();
    try {/*from www  .  j a v a 2 s  . c  om*/
        stream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return array;

}

From source file:Main.java

public static String encodeTobase64(Bitmap image) {
    Bitmap immagex = image;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
    return imageEncoded;
}

From source file:Main.java

public static byte[] bitmapToByteArray(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] bytes = baos.toByteArray();
    try {/*from w  ww.j  a v  a2  s . co  m*/
        baos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return bytes;

}

From source file:Main.java

public static byte[] getFileDataFromBitmap(Context context, Bitmap bitmap) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 0, byteArrayOutputStream);
    return byteArrayOutputStream.toByteArray();
}

From source file:Main.java

/**
 * BitMap2Byte/*from  w  w w.  j  a  v a 2 s  .  c  o  m*/
 *
 * @param bitmap
 * @return
 */
public static byte[] getBitmapByte(Bitmap bitmap) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    try {
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return out.toByteArray();
}

From source file:Main.java

public static byte[] bitmap2Bytes(Bitmap bitmap) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
    return byteArrayOutputStream.toByteArray();
}

From source file:Main.java

public static byte[] Bitmap2Bytes(Bitmap bm, int ratio) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, ratio, baos);
    //add//from  w w  w  .  j a  v  a2 s.co m
    if (bm != null && !bm.isRecycled()) {
        bm.recycle();
        bm = null;
    }
    return baos.toByteArray();
}

From source file:Main.java

public static InputStream convertToInputStream(Bitmap bitmap) {

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);

    byte[] imageInByte = stream.toByteArray();
    System.out.println("........length......" + imageInByte);

    ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);
    return bis;// ww  w .j av  a  2s  .  co m
}