Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.BitmapFactory;

public class Main {
    private static int getScale(String imagePath, int desiredWidth, int desiredHeight) {
        //Get image size
        BitmapFactory.Options imageInfo = new BitmapFactory.Options();
        imageInfo.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(imagePath, imageInfo);

        //Compute the scaling factor
        int scale = 1;
        int width = imageInfo.outWidth;
        int height = imageInfo.outHeight;

        while (width / (scale * 2) >= desiredWidth && height / (scale * 2) >= desiredHeight) {
            scale = scale * 2;
        }

        return scale;
    }
}