Reputation: 170
In my Application when i take the picture from camera, i needs to get the size of that picture and compress it,if it is more than the specified size. how should i know the size of image and compress it according to my application..
Please help me.
Upvotes: 1
Views: 2220
Reputation: 21979
To get the height and width, you call:
Uri imagePath = Uri.fromFile(tempFile);//Uri from camera intent
//Bitmap representation of camera result
Bitmap realImage = BitmapFactory.decodeFile(tempFile.getAbsolutePath());
realImage.getHeight();
realImage.getWidth();
To resize the image, I just supply the resulting Bitmap into this method:
public static Bitmap scaleDown(Bitmap realImage, float maxImageSize,
boolean filter) {
float ratio = Math.min((float) maxImageSize / realImage.getWidth(),
(float) maxImageSize / realImage.getHeight());
int width = Math.round((float) ratio * realImage.getWidth());
int height = Math.round((float) ratio * realImage.getHeight());
Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width, height,
filter);
return newBitmap;
}
The basic actually is just Bitmap.createScaledBitmap()
. However, I wrap it to another method to scale it down proportionally.
Upvotes: 1