I am trying to reduce the size of an image that a user has selected from the Gallery before passing it to another intent.
I am currently using the following code, but i
You can use this code ...
public static Bitmap getThumbnailBitmap(final String path,
final int thumbnailSize) {
Bitmap bitmap;
BitmapFactory.Options bounds = new BitmapFactory.Options();
bounds.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, bounds);
if ((bounds.outWidth == -1) || (bounds.outHeight == -1)) {
bitmap = null;
}
int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight
: bounds.outWidth;
BitmapFactory.Options opts = new BitmapFactory.Options();
if (thumbnailSize > 0) {
opts.inSampleSize = originalSize / thumbnailSize;
} else {
opts.inSampleSize = originalSize;
}
try {
bitmap = BitmapFactory.decodeFile(path, opts);
} catch (Exception ex) {
return null;
}
return bitmap;
}