Here you can find the source of compressToBytes(Bitmap bitmap, int quality)
public static byte[] compressToBytes(Bitmap bitmap, int quality)
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import java.io.ByteArrayOutputStream; public class Main { public static byte[] compressToBytes(Bitmap bitmap, int quality) { ByteArrayOutputStream baos = new ByteArrayOutputStream(65536); bitmap.compress(CompressFormat.JPEG, quality, baos); return baos.toByteArray(); }/*w w w .ja v a 2s . c o m*/ }