calculate In Simple Size By Math for Bitmap Image - Android Graphics

Android examples for Graphics:Bitmap Size

Description

calculate In Simple Size By Math for Bitmap Image

Demo Code


//package com.book2s;

import android.graphics.BitmapFactory;

public class Main {

    public static int calculateInSimpleSizeByMath(int reqWidth,
            int reqHeight, BitmapFactory.Options options) {
        int inSampleSize = 1;
        if (options.outWidth > reqWidth || options.outHeight > reqHeight) {
            int widthRatio = Math.round((float) options.outWidth
                    / (float) reqWidth);
            int heightRatio = Math.round((float) options.outHeight
                    / (float) reqHeight);
            inSampleSize = Math.min(widthRatio, heightRatio);
        }//from  w  w  w .  j  a  v a  2s  .  c o m
        return inSampleSize;
    }
}

Related Tutorials