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.
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.
Of course you can scale:
Bitmap bm = Bitmap.createScaledBitmap(src, dstWidth, dstHeight, filter);
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
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.
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);