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 Answers 4

1

Of course you can scale:

Bitmap bm = Bitmap.createScaledBitmap(src, dstWidth, dstHeight, filter);
Sign up to request clarification or add additional context in comments.

Comments

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);

Comments

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

2 Comments

But my question is can i scale bitmap image or not?
yes off course, and if you just want to scale use bitmap factory stackoverflow.com/questions/9360976/…
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.