Android examples for Graphics:Image Rotate
This method is use for rotation of image.
//package com.java2s; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import java.io.FileNotFoundException; import java.io.FileOutputStream; public class Main { /**//from w w w. j ava 2s . c o m * 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(); } } } } }