Android examples for android.graphics:Image Operation
rotate Image
import java.io.FileNotFoundException; import java.io.FileOutputStream; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; public class Main { /**//from www . ja v a2 s . com * This method is use for rotation of image. * * @param mediaFile * **/ public static void rotateImage(String mediaFile, int rotation) { if (rotation != 0) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; Bitmap bitmap = BitmapFactory.decodeFile(mediaFile, options); if (bitmap != null) { Matrix matrix = new Matrix(); matrix.setRotate(rotation); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); // bitmap.recycle(); try { final FileOutputStream fos = new FileOutputStream(mediaFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); } catch (FileNotFoundException e) { e.printStackTrace(); } } } } }