I found a lot of code about Bitmaps in Android. Change size, change size preserving aspect ratio, compress etc. etc. However I need to change a Bitmap aspect ratio to fit my needs (5:8), programmatically. I have no code to show because any search I made return how to preserve aspect ratio, not to change it. As for example, 5:8 should be width:500 height:800
Asked
Active
Viewed 587 times
0
-
As I can read this is exactly the opposite to my needs. I don't need to preserve the aspect ratio, I need to change the aspect ratio to 5:8 (or any other I should decide) without caring if the image will be deformed. – WizardingStudios Jan 18 '20 at 00:23
-
I stand corrected - Removed – fabfas Jan 18 '20 at 00:31
-
It's the same. Calculate needed width and height, and `newBitmap = Bitmap.createScaledBitmap(oldBitmap, width, height, true);` – Sergey Glotov Jan 18 '20 at 00:33
-
Does this answer your question? [How to Resize a Bitmap in Android?](https://stackoverflow.com/questions/4837715/how-to-resize-a-bitmap-in-android) – Ryan M Jan 18 '20 at 02:10
-
@RyanMentley To resize, yes. However in my answer I also calculate the desired aspect ratio. – WizardingStudios Jan 18 '20 at 08:59
1 Answers
1
Thanks to @SergeyGlotov comment I simply calculated the new size this way:
private Bitmap bitmapChangeAspectRatio(Bitmap bitmap){
int width, height;
width = bitmap.getWidth() / 5;
height = width * 8;
return Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), height, true);
}
I do not delete the question due there is not a clear example of this on the web.

WizardingStudios
- 554
- 2
- 7
- 22