create Scaled BMP by max length - Android Graphics

Android examples for Graphics:Bitmap Scale

Description

create Scaled BMP by max length

Demo Code


//package com.java2s;
import android.graphics.Bitmap;

public class Main {
    public static Bitmap createScaledBMP(Bitmap sourceImg, int maxLength) {
        int width = sourceImg.getWidth();
        int height = sourceImg.getHeight();
        int scaleWidth = width > height ? maxLength : width * maxLength
                / height;//from   www .  j  av a  2s .  c  o m
        int scaleHeight = width > height ? height * maxLength / width
                : maxLength;
        return Bitmap.createScaledBitmap(sourceImg, scaleWidth,
                scaleHeight, true);
    }
}

Related Tutorials