Android examples for Graphics:Bitmap Sample Size
Calculate the sample size in which to load the Bitmap This method makes
//package com.java2s; import android.graphics.BitmapFactory; public class Main { /**/*from w ww. j a v a 2 s.co m*/ * Calculate the sample size in which to load the Bitmap * * This method makes * @param options Options containing the width and height of the image being sampled * @param desiredWidth The desired width of the sampled image * @param desiredHeight the Desired height of the sampled image * @return Sample size */ public static int calculateInSampleSize(BitmapFactory.Options options, int desiredWidth, int desiredHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > desiredHeight || width > desiredWidth) { if (width > height) { inSampleSize = Math.round((float) height / (float) desiredHeight); } else { inSampleSize = Math.round((float) width / (float) desiredWidth); } } return inSampleSize; } }