OutOfMemory exception when loading bitmap from external storage

前端 未结 13 1739
广开言路
广开言路 2020-11-29 06:52

In my application I load a couple of images from JPEG and PNG files. When I place all those files into assets directory and load it in this way, everything is ok:

         


        
13条回答
  •  猫巷女王i
    2020-11-29 07:17

    This is a fairly common issue which all of us face while loading images from the sdcard.

    The solution as I found was to use inJustDecodeBounds first while loading the image using decodeFileDescriptor . That would not actually decode the image, but give the image size. Now I can scale it appropriately(using the options) so as to resize the image for the display area. Its needed because low memory on the phone can be easily taken over by your 5MP image. This I believe is the most elegant solution.

提交回复
热议问题