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 InputStream bitmap2InputStream4Gif(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.WEBP, 100, baos);
    InputStream is = new ByteArrayInputStream(baos.toByteArray());
    return is;/*  ww  w.j  a v a  2s .  c  om*/
}

From source file:Main.java

public static byte[] getBytes(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 0, stream);
    return stream.toByteArray();
}

From source file:Main.java

private static String getStringImage(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 encodedImage;
}

From source file:Main.java

public static byte[] getBitmapData(Bitmap bmp) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bmp.compress(CompressFormat.JPEG, 100, bos);
    byte[] bitmapdata = bos.toByteArray();

    return bitmapdata;
}

From source file:Main.java

public static String BitmapToBase64PNG(Bitmap bmp) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 40, baos);
    byte[] data = baos.toByteArray();
    return Base64.encodeToString(data, Base64.DEFAULT);
}

From source file:Main.java

public static byte[] bitmapToBytes(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    return stream.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 w w  . j a v a  2  s.  com*/
}

From source file:Main.java

public static int getBmpSize(Bitmap bmp) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    return b.length;
}

From source file:Main.java

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

From source file:Main.java

/**
 * bitmap2Bytes/* ww  w .  j  a  v a 2s .  co  m*/
 *
 * @param bm
 * @return
 */
public static byte[] bitmap2Bytes(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
    return baos.toByteArray();
}