Answers for "how to set height and width of image in android programmatically"

3

how to resize image in android programmatically

public static Bitmap resizeImage(Bitmap realImage, float maxImageSize,
        boolean filter) {
    float ratio = Math.min(
            (float) maxImageSize / realImage.getWidth(),
            (float) maxImageSize / realImage.getHeight());
    int width = Math.round((float) ratio * realImage.getWidth());
    int height = Math.round((float) ratio * realImage.getHeight());

    Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width,
            height, filter);
    return newBitmap;
}
Posted by: Guest on January-15-2021

Code answers related to "how to set height and width of image in android programmatically"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language