Android Bitmap Scale getScaledBitmap(String picturePath, int width, int height)

Here you can find the source of getScaledBitmap(String picturePath, int width, int height)

Description

get Scaled Bitmap

Declaration

public static Bitmap getScaledBitmap(String picturePath, int width,
            int height) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

public class Main {
    public static Bitmap getScaledBitmap(String picturePath, int width,
            int height) {
        // Get the dimensions of the bitmap
        BitmapFactory.Options bmOptions = new BitmapFactory.Options();
        bmOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(picturePath, bmOptions);
        int photoW = bmOptions.outWidth;
        int photoH = bmOptions.outHeight;

        // Determine how much to scale down the image
        int scaleFactor;

        if (width > 0 && height > 0) {
            scaleFactor = Math.min(photoW / width, photoH / height);
        } else {/* w w  w .ja  v a2 s.  c  o  m*/
            scaleFactor = 1;
        }

        // Decode the image file into a Bitmap sized to fill the View
        bmOptions.inJustDecodeBounds = false;
        bmOptions.inSampleSize = scaleFactor;
        bmOptions.inPurgeable = true;

        return BitmapFactory.decodeFile(picturePath, bmOptions);
    }
}

Related

  1. scaleToFit(Bitmap bm, float width_Ratio, float height_Ratio)
  2. stretchImage(Bitmap image, float xscale, float yscale)
  3. stretchImage(Bitmap image, int xsize, int ysize)
  4. zoomImg(Bitmap bm, int newWidth, int newHeight)
  5. getSmallBitmap(String filePath)
  6. cleanStretchImage(Bitmap image, int xsize, int ysize)
  7. cleanStretchImageY(Bitmap image, int ysize)