get Scale Bitmap By Path - Android android.graphics

Android examples for android.graphics:Bitmap Operation

Description

get Scale Bitmap By Path

Demo Code


//package com.java2s;

import android.content.Context;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {
    public static Bitmap getScaleBitmapByPath(String path, Context context,
            int w) {
        Bitmap bitmap;/*from  w w w  . j a v  a2  s  .  co  m*/
        int meaW;
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        bitmap = BitmapFactory.decodeFile(path, options);
        meaW = options.outWidth;
        if (meaW > w) {
            options.inSampleSize = meaW / w;
            options.inJustDecodeBounds = false;
            bitmap = BitmapFactory.decodeFile(path, options);
        } else {
            bitmap = BitmapFactory.decodeFile(path);
        }
        return bitmap;
    }
}

Related Tutorials