change bitmap size based device Android Studio

Viewed 63

return of

BitmapFactory.decodeResource(getResources(), R.drawable.basictiles)

change based on device.

Pixel:

size = 1.792.000

height, width = 1120,400

SM-G900F

size = 2.580.480

height, width = 1344,480

I want the same return for every device

2 Answers

put your R.drawable.basictiles file inside drawable-nodpi folder

another approach is to use new BitmapFactory.Options() when decodeResource (third param) and set inScaled param to false

You may want to look at:

BitmapFactory.decodeResource(Resources res, int id, BitmapFactory.Options opts)

You can find it here

Essentially you need to pass in BitmapFactory.Options which can be used to control the resulting scaling, width, height etc of the Bitmap

BitmapFactory.Options options = new BitmapFactory.Options();
options.outHeight = ;// the height you want 
options.outWidth = ;// the width you want
BitmapFactory.decodeResource(getResources(), R.drawable.basictiles, options);
Related