OutOfMemoryError with image selection in Android. How to resize image before decoding it to bitmap?

后端 未结 5 1633
深忆病人
深忆病人 2021-01-16 17:52

I\'m building an imagepicker in my Android app, for which I used the example code on this page. This basically gives me a button which opens the possibility to get a file fr

5条回答
  •  不知归路
    2021-01-16 18:48

    You can use image sampling which is loading the smaller size image without having to load the bigger one. You can do that with Options argument passed to BitmapFactory. Set Options.inJustDecodeBounds true and BitmapFactory will set Options.outWidth and Options.outHeight fields to image's original size. Note that when setting inJustDecodeBounds to true the returned Bitmap is null. Also use Options.inSampleSize to decode sampled image. Sample size shows how much the result image is scaled down.

提交回复
热议问题