Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change bitmap size based device Android Studio [closed]

In android studio the return value of this function BitmapFactory.decodeResource(getResources(), R.drawable.basictiles) changes based on device size.

as and example

Pixel:

  • size = 1.792.000
  • height, width = 1120,400

SM-G900F

  • size = 2.580.480
  • height, width = 1344,480

I'm trying to find a way to get the same image size for every device/resolution.

like image 877
Alberto Zanovello Avatar asked Apr 19 '26 05:04

Alberto Zanovello


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

like image 182
snachmsm Avatar answered Apr 20 '26 19:04

snachmsm


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);
like image 27
David Kroukamp Avatar answered Apr 20 '26 18:04

David Kroukamp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!