-1

I have images of size 1080P , now i do not want to use different variations of images that we put in RES folder . I am going to install this app on 1K devices with random images , so thats not feasible to have different versions of images.

Can we scale it on runtime , still getting the best quality ?

navjosh
  • 187
  • 2
  • 2
  • 13

1 Answers1

2

To scale images use following

Bitmap bitmap = BitmapFactory.decodeResource(
                getResources(), R.drawable.app_bg);
scaledBitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);

then assign this scaledBitmap to any ImageView or any other View. This will scale the original Bitmap to the requested width and height. To get width and height of the device screen use following

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

EDIT
In order to handle MemoryLeakException add scaledBitmap.recycle() after using this Bitmap.

Atif Farrukh
  • 2,219
  • 2
  • 25
  • 47