compute Bitmap Initial Sample Size - Android Graphics

Android examples for Graphics:Bitmap Sample Size

Description

compute Bitmap Initial Sample Size

Demo Code


//package com.java2s;

import android.graphics.BitmapFactory.Options;

public class Main {
    private static int computeInitialSampleSize(Options opts,
            int minSideLength, int maxNumOfPixels) {
        double w = opts.outWidth;
        double h = opts.outHeight;
        int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(w * h
                / maxNumOfPixels);//from w  ww  . j  a  v  a2 s.  c  o m
        int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(
                Math.floor(w / minSideLength),
                Math.floor(h / minSideLength));
        if (upperBound < lowerBound) {
            return lowerBound;
        }
        if ((maxNumOfPixels == -1) && (minSideLength == -1)) {
            return 1;
        } else if (minSideLength == -1) {
            return lowerBound;
        } else {
            return upperBound;
        }
    }
}

Related Tutorials