Get the sampling size for load the bitmap. - Android Graphics

Android examples for Graphics:Bitmap Size

Description

Get the sampling size for load the bitmap.

Demo Code


//package com.java2s;

public class Main {

    public static int getSafeResizingSampleSize(int nOrgWidth,
            int nOrgHeight, int nMaxWidth, int nMaxHeight) {
        int size = 1;
        float fsize;
        float fWidthScale = 0;
        float fHeightScale = 0;

        if (nOrgWidth > nMaxWidth || nOrgHeight > nMaxHeight) {
            if (nOrgWidth > nMaxWidth)
                fWidthScale = (float) nOrgWidth / (float) nMaxWidth;
            if (nOrgHeight > nMaxHeight)
                fHeightScale = (float) nOrgHeight / (float) nMaxHeight;

            if (fWidthScale >= fHeightScale)
                fsize = fWidthScale;/*from  w  w w. ja  va 2s.  c o m*/
            else
                fsize = fHeightScale;

            size = (int) fsize;
        }

        return size;
    }
}

Related Tutorials