Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.graphics.Bitmap;

public class Main {
    /**
     * Since max texture size is 4Kx4K, we have to size it down. Also, no new phones have screens wider than 1440px, but there will be no difference for 1080p width, so we resize to that
     * @param toResize - bitmap to resize
     * @return resized bitmap
     */
    public static Bitmap resizeForPreview(Bitmap toResize) {
        final int maxSize = 1024;
        int width = toResize.getWidth();
        int height = toResize.getHeight();
        int newWidth = width, newHeight = height;

        if (width > height && width > maxSize) {
            newWidth = maxSize;
            newHeight = (height * maxSize) / width;
        } else if (height > maxSize) {
            newHeight = maxSize;
            newWidth = (width * maxSize) / height;
        }

        return Bitmap.createScaledBitmap(toResize, newWidth, newHeight, false);
    }
}