WizardingStudios
WizardingStudios

Reputation: 572

Android, change Bitmap aspect ratio programmatically

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

Upvotes: 0

Views: 703

Answers (1)

WizardingStudios
WizardingStudios

Reputation: 572

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.

Upvotes: 1

Related Questions