change bitmap resolution in Android app

后端 未结 3 1905
日久生厌
日久生厌 2021-01-14 08:16

I\'m writing an application that uses the phone\'s camera to take a picture, and then use it in my app. The thing is, the app runs out of memory, and it is probably because

3条回答
  •  一向
    一向 (楼主)
    2021-01-14 08:59

    from jeet.chanchawat' s answer: https://stackoverflow.com/a/10703256/3027225

      public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
            int width = bm.getWidth();
            int height = bm.getHeight();
            float scaleWidth = ((float) newWidth) / width;
            float scaleHeight = ((float) newHeight) / height;
            // CREATE A MATRIX FOR THE MANIPULATION
            Matrix matrix = new Matrix();
            // RESIZE THE BIT MAP
            matrix.postScale(scaleWidth, scaleHeight);
    
            // "RECREATE" THE NEW BITMAP
            Bitmap resizedBitmap = Bitmap.createBitmap(
                bm, 0, 0, width, height, matrix, false);
            return resizedBitmap;
        }
    

提交回复
热议问题