Here you can find the source of scaleBitmap(Bitmap bitmap, int targetwidth)
public static Bitmap scaleBitmap(Bitmap bitmap, int targetwidth)
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Picture; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.ParcelFileDescriptor; import android.view.View; import android.webkit.WebView; import android.widget.ScrollView; public class Main{ public static Bitmap scaleBitmap(Bitmap bitmap, int targetwidth) { int imageWidth = targetwidth; if (bitmap != null && (bitmap.getWidth() < imageWidth || bitmap.getHeight() < imageWidth)) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int min = width; if (width > height) { min = height;//from w w w . j av a 2 s .c o m } float scale = imageWidth / min; bitmap = BitmapUtils.zoomBitmap(bitmap, (int) (width * scale), (int) (height * scale)); } return bitmap; } public static Bitmap zoomBitmap(Bitmap bitmap, int width, int height) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix matrix = new Matrix(); float scaleWidth = ((float) width / w); float scaleHeight = ((float) height / h); matrix.postScale(scaleWidth, scaleHeight); Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true); return newbmp; } }