0

I try to resize bitmap from gallery.I wrote some code and i can resize bitmap only static width and height.this is source

     public Bitmap getResizedBitmap(Bitmap bm, int newWidth) {

    float aspectRatio = (float)bm.getWidth() / (float) bm.getHeight();
    int height = Math.round(newWidth / aspectRatio); //based on width it gives height
    Matrix matrix = new Matrix();

    matrix.postScale(newWidth, height);

    Bitmap resizedBitmap = Bitmap.createBitmap(
            bm, 0, 0, newWidth, height, matrix, false);
    return resizedBitmap;
}

but i want to resize bitmap for example width 800px and auto height.is it a possible to solve this problem in android ? thanks

BekaKK
  • 2,173
  • 6
  • 42
  • 80
  • [refer this link](http://stackoverflow.com/questions/3331527/android-resize-a-large-bitmap-file-to-scaled-output-file) i also got solution for same problem from this link – Prashant Jajal Nov 07 '16 at 10:58

2 Answers2

4
float aspectRatio = (float)Image.getWidth() / (float) Image.getHeight();
int width = 200;    //your width
int height = Math.round(width / aspectRatio); //based on width it gives height
sasikumar
  • 12,540
  • 3
  • 28
  • 48
1
public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
int width = bm.getWidth();
int height = bm.getHeight();
Bitmap resizedBitmap;


try {
         resizedBitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight());
            }catch (Exception e){
                e.printStackTrace();
                boolean_image = true;
                return "";

            }

return resizedBitmap;
}
Deepshikha Puri
  • 2,104
  • 22
  • 23