OutOfMemory exception when loading bitmap from external storage

前端 未结 13 1721
广开言路
广开言路 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条回答
  •  借酒劲吻你
    2020-11-29 07:15

    • When doing a lot with bitmaps, don't debug the app - just run it. The debugger will leave memory leaks.
    • Bitmaps are very expensive. If possible, scale them down on load by creating BitmapFactory.Options and setting inSampleSize to >1.

    EDIT: Also, be sure to check your app for memory leaks. Leaking a Bitmap (having static Bitmaps is an excellent way to do that) will quickly exhaust your available memory.

提交回复
热议问题