Java tutorial
//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); } }