Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; public class Main { public static Bitmap scaleBitmap(int height, int width, String pathImage) { Bitmap desBitmap = null; BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(pathImage, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image int scaleFactor = Math.min(photoW / width, photoH / height); // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor << 1; bmOptions.inPurgeable = true; Bitmap bitmap = BitmapFactory.decodeFile(pathImage, bmOptions); Matrix mtx = new Matrix(); mtx.postRotate(90); // Rotating Bitmap Bitmap rotatedBMP = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), mtx, true); if (rotatedBMP != bitmap) { bitmap.recycle(); } return rotatedBMP; } }