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[] bitmapToByteArray(Bitmap bmp) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(CompressFormat.JPEG, 60, stream);
    byte[] byteArray = stream.toByteArray();

    return byteArray;
}

From source file:Main.java

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

From source file:Main.java

public static String bitMapToString(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] b = baos.toByteArray();
    String temp = Base64.encodeToString(b, Base64.DEFAULT);
    return temp;/* w  w w . ja  v a2  s  .c  om*/
}

From source file:Main.java

public static byte[] bitmapToByteArray(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 getInputStreamValue(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    InputStream in = new ByteArrayInputStream(stream.toByteArray());
    return in;//from w w w. jav a 2s .  c  o m
}

From source file:Main.java

public static byte[] bitmapToByte(Bitmap bitmap) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] yy = baos.toByteArray();
    return yy;//ww  w.j  a  va2s .  c om
}

From source file:Main.java

public static String bitmapToBase64(Bitmap bitmap) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes);
    byte[] byteArr = bytes.toByteArray();
    return Base64.encodeToString(byteArr, Base64.DEFAULT);
}

From source file:Main.java

public static String BitMapToString(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] arr = baos.toByteArray();
    String result = Base64.encodeToString(arr, Base64.DEFAULT);
    return result;
}

From source file:Main.java

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