private static int getScaleFactor(ImageMetadata metadata, int minW, int minH) {
        int scale = 1;
        int scaledW = metadata.getW();
        int scaledH = metadata.getH();
        while (scaledW / 2 > minW && scaledH / 2 > minH) {
            scale *= 2;
            scaledH /= 2;
            scaledW /= 2;
        }
        return scale;
    }
private static int getScaleFactor ( ImageMetadata metadata , int minW , int minH ) { int scale = 1 ; int scaledW = metadata . getW ( ) ; int scaledH = metadata . getH ( ) ; while ( scaledW / 2 > minW && scaledH / 2 > minH ) { scale *= 2 ; scaledH /= 2 ; scaledW /= 2 ; } return scale ; }
Calculating scale factor with limit of pixel amount

@param metadata image metadata
@param minH     minimal height
@param minW     minimal width
@return scale factor