2

Please suggest me the way to rotate the bitmap image in android.

I have following sample but when I rotate the image with 10 degrees it gets black at corners as well as size of image is increased.

When i rotate image continuously with 10 degrees it throw memory out of bound exception.

private void rotateImage(String sourcePath, float angle) {
    Bitmap bitmap = BitmapFactory.decodeFile(sourcePath);
    Matrix matrix = new Matrix();
    matrix.setRotate(angle);
    Bitmap rotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    File file = new File(sourcePath);
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(file);
        rotated.compress(Bitmap.CompressFormat.PNG, 85, fOut);
        fOut.flush();
        fOut.close();
        bitmap.recycle();
        rotated.recycle();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Rahul Giradkar
  • 1,818
  • 1
  • 17
  • 28

1 Answers1

1

Try ExifInterface for image rotation

check this solution for details, how to use ExifInterface

See more info about Exif

Rohan Pawar
  • 1,875
  • 22
  • 40