Android Utililty Methods Bitmap Compress

List of utility methods to do Bitmap Compress

Description

The list of methods to do Bitmap Compress are organized into topic(s).

Method

byte[]compressToBytes(Bitmap bitmap, int quality)
compress To Bytes
ByteArrayOutputStream baos = new ByteArrayOutputStream(65536);
bitmap.compress(CompressFormat.JPEG, quality, baos);
return baos.toByteArray();
voidcompress(String srcPath, String dstPath, int maxWidth, int maxHeight, long maxSize, CompressFormat format)
compress
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeFile(srcPath, opts);
opts.inJustDecodeBounds = false;
int w = opts.outWidth;
int h = opts.outHeight;
int size = 0;
if (w <= maxWidth && h <= maxHeight) {
...
voidcompress(byte[] data, String dstPath, int maxWidth, int maxHeight, long maxSize, CompressFormat format)
compress
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,
        opts);
opts.inJustDecodeBounds = false;
int w = opts.outWidth;
int h = opts.outHeight;
int size = 0;
...
byte[]decodeToCompressedByteArray(String imageUri)
decode To Compressed Byte Array
Bitmap bitmapOrg = BitmapFactory.decodeFile(imageUri);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 99, bao);
byte[] ba = bao.toByteArray();
return ba;
BitmapdownsampleBitmap(FileDescriptor fd, int maxArea)
downsample Bitmap
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
Rect outRect = new Rect();
BitmapFactory.decodeFileDescriptor(fd, outRect, opts);
int subsample = 1;
int width = opts.outWidth;
int height = opts.outHeight;
while (width * height > maxArea) {
...