List of utility methods to do Bitmap Compress
byte[] | compressToBytes(Bitmap bitmap, int quality) compress To Bytes ByteArrayOutputStream baos = new ByteArrayOutputStream(65536); bitmap.compress(CompressFormat.JPEG, quality, baos); return baos.toByteArray(); |
void | compress(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) { ... |
void | compress(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; |
Bitmap | downsampleBitmap(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) { ... |