Code example for Bitmap

Methods: getHeightgetWidthhasAlpha

0
     * @return A bitmap that fits the maximum dimensions. 
     */ 
    @SuppressWarnings({"SuspiciousNameCombination"}) 
    @VisibleForTesting 
    static Bitmap getNormalizedBitmap(Bitmap original, int maxDim, boolean forceCropToSquare) {
        final boolean originalHasAlpha = original.hasAlpha();
 
        // All cropXxx's are in the original coordinate. 
        int cropWidth = original.getWidth();
        int cropHeight = original.getHeight();
        int cropLeft = 0;
        int cropTop = 0;
        if (forceCropToSquare && cropWidth != cropHeight) {
            // Crop the image to the square at its center. 
            if (cropHeight > cropWidth) {
                cropTop = (cropHeight - cropWidth) / 2;
                cropHeight = cropWidth;
            } else { 
                cropLeft = (cropWidth - cropHeight) / 2;
                cropWidth = cropHeight;