Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 333
Tushar Kathuria Avatar asked Jan 17 '26 23:01

Tushar Kathuria


1 Answers

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

like image 161
CommonsWare Avatar answered Jan 20 '26 13:01

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!