Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.Bitmap;

import android.util.Log;
import android.util.SparseArray;

import java.util.Map;

public class Main {
    public static void scaleBitmaps(Map<Integer, Bitmap> bitmapMap, float scale) {
        for (Integer key : bitmapMap.keySet()) {
            Bitmap bitmap = bitmapMap.get(key);
            bitmapMap.put(key, scaleBitmap(bitmap, scale));
        }
    }

    public static void scaleBitmaps(SparseArray<Bitmap> bitmapMap, float scale) {
        for (int i = 0; i < bitmapMap.size(); i++) {
            int key = bitmapMap.keyAt(i);
            Log.d("BitmapUtil", "scaleBitmaps: " + key);
            Bitmap bitmap = bitmapMap.get(key);
            bitmapMap.put(i, scaleBitmap(bitmap, scale));
        }
    }

    public static Bitmap scaleBitmap(Bitmap bitmap, float scale) {
        int width = (int) ((float) bitmap.getWidth() * scale);
        int height = (int) ((float) bitmap.getHeight() * scale);
        if (bitmap.getWidth() != width || bitmap.getHeight() != height) {
            return Bitmap.createScaledBitmap(bitmap, width, height, true /* filter */);
        } else {
            return bitmap;
        }
    }
}