Deal with the different size images while getting from server in different mobile dimensions?

267 Views Asked by At

I am working on the project in which i make the call to server and getting the information including pictures. I also have to support different dimensions of mobile and tablet. In this case, I am doing in such a way that

  1. I am getting the mobile dimensions and send to server.
  2. Based on the mobile dimensions server send the images.
  3. This technique will increase the performance to load the images in different mobile faster. And in this technique server also not have big deal to handle.

Is it good what i am doing or any other way?

1

There are 1 best solutions below

7
vguzzi On

I found an easier way of dealing with generating different sizes of Drawables from one server image.

You should keep how ever many 'template' images within your project inside the appropriate Drawables folders, you would need as many different templates as you need different sized images, for example if you only ever have one size of image coming back from the server i.e a thumbnail image then you'll only need a thumbnail template, if you have a thumbnail and a larger display image which could come back then you'll then need two templates.

You should then get the server to only hold and send back the largest images i.e xxxhdpi. When you receive the xxxhdpi image from the server you should then re-size your image to the same height and width of your template image (which the system will choose depending on the users screen-size). This allows you to utilize the power of Drawables in Android whilst keeping your server payload low by only needing to send one image and also allows you to keep your apk light as you only need to store a few template images within your project. This can also work if you have to deal with .obb files which can't store Drawables.

Hope this helps. Let me know if you need me to explain anything in more detail or you're worried about how something would work, I've got a couple of live apps out which use this method.