1

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.

Arun Joshi
  • 170
  • 1
  • 1
  • 10

1 Answers1

1

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.

ariefbayu
  • 21,849
  • 12
  • 71
  • 92
  • Thanks silent for your suggestion but how should i able to know that size of captured image. and what id the use of Boolean variable filter in this method. – Arun Joshi Jun 11 '12 at 06:40
  • the `filter` is explained here: http://stackoverflow.com/questions/2895065/what-does-the-filter-parameter-to-createscaledbitmap-do – ariefbayu Jun 11 '12 at 06:46