Tushar Kathuria
Tushar Kathuria

Reputation: 655

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?

Upvotes: 2

Views: 1371

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007658

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

Upvotes: 13

Related Questions