Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {
    public static Bitmap getScaleBitmap(Context context, String filePath) {
        BitmapFactory.Options opts = new BitmapFactory.Options();

        opts.inJustDecodeBounds = true;
        Bitmap bitmap = BitmapFactory.decodeFile(filePath, opts);
        opts.inJustDecodeBounds = false;
        int ratio = (int) (opts.outHeight / (float) 200);
        if (ratio <= 0)
            ratio = 1;
        opts.inSampleSize = ratio;
        bitmap = BitmapFactory.decodeFile(filePath, opts);
        return bitmap;
    }
}