I am trying to calculate an aspect ratio for an image:
Log.d("img.width:", String.valueOf(img.getIntrinsicWidth()));
Log.d("img.height:", String.valueOf(img.getIntrinsicHeight()));
float aspect = ((float)img.getIntrinsicWidth()) / ((float)img.getIntrinsicWidth());
Log.d("aspect:", String.valueOf(aspect));
however this produces unexpected results:
img.width: 297
img.height: 167
aspect: 1.0
This seems like it has a simple answer, yet I can't figure it out.
You're dividing width by width. Try substituting one of them with the height.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With