Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.Bitmap;

import android.media.ThumbnailUtils;

public class Main {

    public static Bitmap compressAccordingToWidth(Bitmap bitmap, int width) {

        if (width == bitmap.getWidth()) {
            return bitmap;
        }

        float scale = (float) width / (float) bitmap.getWidth();
        int height = (int) (bitmap.getHeight() * scale);

        return ThumbnailUtils.extractThumbnail(bitmap, width, height, 0);
    }
}