-2

Is it Ok to provide image resources for all densities in Android (LDPI, MDPI, HDPI...) and that the system can choose the appropriate one for each device, or it is more efficient to provide only high resolution ones and downscale them to devices with lower resolution? In the last case, can the system itself do the downsampling, or will it cause a lot of OutOfMemory errors and slow performance. On the other hand, you can do downsample the images using the right classes that provide the Android SDK, but will you have to downsample each time you load the app? Any help will be appreciated.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
TonyL
  • 115
  • 8
  • 1
    This question can easily be answered if you take a look at the [documentation](https://developer.android.com/training/multiscreen/screendensities.html#TaskProvideAltBmp) – Nicolás Carrasco-Stevenson Feb 27 '18 at 11:15
  • Of course it is well looked. It is the way I am using now for decoding the resources. But this way you increase the APK file by 4, you don't have control over exactly the right resource for different families of devices sharing the same density, and if you look at top apps, they only include one image for all densities. – TonyL Feb 27 '18 at 11:18
  • You may want to use drawables, 9 patches, SVGs, vectordrawables, icon fonts, and all the sorts of scalable resources to provide a single instance of your resources. – Phantômaxx Feb 27 '18 at 11:56

3 Answers3

1

Instead of using a raw image format, you can use a Vector Graphics instead
Your default android application's icon is actually a vector resource
enter image description here

More guidelines about this can be found here:
Add Multi-Density Vector Graphics

Tuấn Kiệt
  • 312
  • 3
  • 13
1

Yes, providing different scales would be the more appropriate way. Yes again as downscaling an image isn't efficient as it slows down the app and also gives memory exception. But that's setting the resource directly using ImageView. As other open sources like Picasso can be used to fit the resource in the view (still slow). Now, having separate scales for a particular image is best. As you don't have to programmatically get the user's device's resolution and adjust scaling because the app will automatically choose the best scale from the folders (faster way). You don't even have to worry about memory exception. It's like no work. You just have to keep necessary scales of the resource in your drawable and you're good to go. You can always find online converters, they rescale your resource to all scales and upload it in a . zip file. Good luck!

Faisal
  • 86
  • 1
  • 8
0

You can also use single Vector image for resources to reduce your apk size

Nits24
  • 11
  • 1