Android Dimension Resize getResizedDimension(int maxPrimary, int maxSecondary, int actualPrimary, int actualSecondary)

Here you can find the source of getResizedDimension(int maxPrimary, int maxSecondary, int actualPrimary, int actualSecondary)

Description

get Resized Dimension

Declaration

static final int getResizedDimension(int maxPrimary, int maxSecondary,
            int actualPrimary, int actualSecondary) 

Method Source Code

//package com.java2s;

public class Main {
    static final int getResizedDimension(int maxPrimary, int maxSecondary,
            int actualPrimary, int actualSecondary) {
        if (maxPrimary == 0 && maxSecondary == 0) {
            return actualPrimary;
        }//ww w .ja  v  a  2  s . co  m

        if (maxPrimary == 0) {
            double ratio = (double) maxSecondary / (double) actualSecondary;
            return (int) (actualPrimary * ratio);
        }

        if (maxSecondary == 0) {
            return maxPrimary;
        }

        double ratio = (double) actualSecondary / (double) actualPrimary;
        int resized = maxPrimary;
        if (resized * ratio > maxSecondary) {
            resized = (int) (maxSecondary / ratio);
        }
        return resized;
    }
}