0

I have a URI of an image that I am trying to load into an imageView.

Uri imageUri = /* URI goes here */
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
Imageview iv = (Imageview) findViewById (R.id.my_img_view);
iv.setImageBitmap(bitmap); 

The image loads in its the full resolution (as large as 21 megapixels causing out of memory exception). My app does not need to utilize the full resolution images so I want the image to be scaled down such a way so that the following conditions are met:

  1. If image height is larger than the width (i.e. portrait) then scale the width to 1024 pixels, and scale the height to appropriate value to maintain aspect ratio.

  2. If the image width is larger than the height (i.e. landscape) then scale the height to 1024 pixels, and scale the width to the appropriate value to maintain aspect ratio.

  3. If the image is square, scale it to 1024x1024

is there any way by which I can scale the bitmap before applying it to the imageView (or even better before Media.getBitmap)?

MurugananthamS
  • 2,395
  • 4
  • 20
  • 49
Bluemarble
  • 1,925
  • 4
  • 20
  • 35

1 Answers1

0

Try this library: https://github.com/AndroidDeveloperLB/AndroidJniBitmapOperations

This library covers almost all bitmap operations like scaling,rotating,cropping..etc

Shishir Shetty
  • 2,021
  • 3
  • 20
  • 35
  • @BuggyCoder - If you go with this answer, you might want to take a look at this question: http://stackoverflow.com/questions/18250951/jni-bitmap-operations-for-helping-to-avoid-oom-when-using-large-images – HaemEternal May 14 '15 at 10:35
  • Umm, do I really have to use 3rd party libraries for a basic task like resizing an image? sometimes I wonder why basic features in android are so complicated :-/ – Bluemarble May 14 '15 at 10:43
  • 1
    I found some solution here. http://stackoverflow.com/questions/4837715/how-to-resize-a-bitmap-in-android – Bluemarble May 14 '15 at 10:52