Search code examples
androidandroid-drawableandroid-image

What is the difference between putting images in drawable and drawable-nodpi folder?


When I put the image in drawable folder, I get OutOfMemoryError while setting the image resource, but after moving the same image to drawable-nodpi folder that error is resolved. How is error resolved on moving the image to drawable-nodpi folder?


Solution

  • res/drawable/ is a legacy synonym for res/drawable-mdpi/, indicating that the drawables in that directory are set for mdpi density. If the device is running another density, those images will be downsampled (to ldpi) or upsampled (to anything else) to match the device density.

    res/drawable-nodpi/ says "these drawables should not be resampled for any density, but instead should be used as-is on all densities".

    If you are getting an OutOfMemoryError that clears up when you move the image to res/drawable-nodpi/, that indicates two things:

    1. The image is probably too large to begin with

    2. Upsampling the image to a higher density failed, because there was no block of memory big enough for the larger upsampled image