Android: Question about Bitmaps, memory usage, and scaling

前端 未结 3 1867
野性不改
野性不改 2021-02-02 17:01

For readibility, I posted the code examples that my solutions refer to first, and thenI listed the explanations of my solutions in a numerical list.

I have been

3条回答
  •  耶瑟儿~
    2021-02-02 17:28

    A simple and straightforward way is to use "inJustDecodeBounds" property of Options. Set this property to true for options object you created, then continue to decode stream.

    The bitmap returned will be null, which means no memory is allocated to it, but you can read the dimensions of the bitmap and thus determine its size and adjust the inSampleSize ratio.

    Later reset inJustDecodeBounds to false, by now you know the scale down factor, thus bitmap of required size can now be generated.

    Hope this helps.

提交回复
热议问题