Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.graphics.Bitmap;

import android.support.annotation.NonNull;

public class Main {
    /**
     * Scale down the bitmap in order to make color analysis faster. Taken from Palette.
     */
    private static Bitmap scaleBitmapDown(@NonNull Bitmap bitmap) {
        final int CALCULATE_BITMAP_MIN_DIMENSION = 100;
        final int minDimension = Math.min(bitmap.getWidth(), bitmap.getHeight());

        if (minDimension <= CALCULATE_BITMAP_MIN_DIMENSION) {
            // If the bitmap is small enough already, just return it
            return bitmap;
        }

        final float scaleRatio = CALCULATE_BITMAP_MIN_DIMENSION / (float) minDimension;
        return Bitmap.createScaledBitmap(bitmap, Math.round(bitmap.getWidth() * scaleRatio),
                Math.round(bitmap.getHeight() * scaleRatio), false);
    }
}