find Best Sample Size for Bitmap - Android Graphics

Android examples for Graphics:Bitmap Sample Size

Description

find Best Sample Size for Bitmap

Demo Code


//package com.java2s;

public class Main {

    public static int findBestSampleSize(int actualWidth, int actualHeight,
            int desiredWidth, int desiredHeight) {
        double wr = (double) actualWidth / desiredWidth;
        double hr = (double) actualHeight / desiredHeight;
        double ratio = Math.min(wr, hr);
        float n = 1.0f;
        while ((n * 2) <= ratio) {
            n *= 2;//from  w  w  w  . j  a v a 2 s  .  c  o  m
        }
        return (int) n;
    }
}

Related Tutorials