class ImageService {

    public static int calculateInSampleSize(final int nativeWidth, int requestedWidth) {
        int inSampleSize = 1;

        if (nativeWidth > requestedWidth) {
            final int halfWidth = nativeWidth / 2;

            while ((halfWidth / inSampleSize) >= requestedWidth) {
                inSampleSize *= 2;
            }
        }

        return inSampleSize;
    }

}