try this code:
/**
* reduces the size of the image
* @param image
* @param maxSize
* @return
*/
public Bitmap getResizedBitmap(Bitmap image, int maxSize) {
int width = image.getWidth();
int height = image.getHeight();
float bitmapRatio = (float)width / (float) height;
if (bitmapRatio > 0) {
width = maxSize;
height = (int) (width / bitmapRatio);
} else {
height = maxSize;
width = (int) (height * bitmapRatio);
}
return Bitmap.createScaledBitmap(image, width, height, true);
}
use it like:
Bitmap scaledImage = getResizedBitmap(photo, 300); //here 300 is maxsize
From Wikipedia
For highest quality images (Q=100), about 8.25 bits per color pixel is required
So, for Q=100
on an 300x300
image, that would result in (300 * 300) px * 8.25 bits/px = 741,500 bits = ~ 91 kB which is surely less than 200KB
you can try for other dimension too..
you can also try to make an image using the bitmap and compare the actual size of the image..
here is the code:
//create a file to write bitmap data
File f = new File(context.getCacheDir(), filename);
f.createNewFile();
//Convert bitmap to byte array
Bitmap bitmap = your bitmap;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();
//write the bytes in file
FileOutputStream fos = new FileOutputStream(f);
fos.write(bitmapdata);
fos.flush();
fos.close();