0

I want to increase size of image. i get image with this code BitmapFactory.decodeResource(getResources(), R.drawable.car);

But this image has different size on different screens, so i want to resize image according to screen size.

4 Answers4

1

Of course you can scale:

Bitmap bm = Bitmap.createScaledBitmap(src, dstWidth, dstHeight, filter);
Shimon Rachlenko
  • 5,469
  • 40
  • 51
JustDoingIt
  • 146
  • 4
0

In android, one should store each resources in at least 3 formats, xhdpi, hdpi and mdpi considering that you have stored a resource's copy in all the 3 formats at their respective folders.

res/drawable-mdpi/my_icon.png // bitmap for medium density res/drawable-hdpi/my_icon.png // bitmap for high density res/drawable-xhdpi/my_icon.png // bitmap for extra high density

The platform is enough smart to pick up right resources according to right screen size on its own.

I don't think you'll face any issues, if you have proper images in all 3 folders.

http://developer.android.com/guide/practices/screens_support.html

Brij Raj Singh - MSFT
  • 4,903
  • 7
  • 36
  • 55
0

Look at http://square.github.io/picasso/ you can download, set where you want the image and resize it, just in one line. It also allows disk caching.

gderaco
  • 2,322
  • 1
  • 16
  • 18
0

Yes you can do this by using the following code snippets, the first section retrns the width and height of the current screen, the second section re-sizes the image.

// This will return the screen size in pixels
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

// Use this to bind and re-size the image
Bitmap car;
car = BitmapFactory.decodeResource(getResources(), R.drawable.car);
car = Bitmap.createScaledBitmap(car, width, height, true);
SingleWave Games
  • 2,618
  • 9
  • 36
  • 52