I am trying to rotate an image from sdcard and then save back to sdcard.
I can do that for “.jpg” format by using ExifInterface class:
exif = new ExifInterface(filepath);
exif.setAttribute(ExifInterface.TAG_ORIENTATION, Integer.toString(orientation));
exif.saveAttributes();
For “.png” files, I would have to actually rotate and save:
Bitmap bitmap = BitmapFactory.decodeFile(filepath);
Matrix matrix = new Matrix();
matrix.postRotate(degrees);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
FileOutputStream stream = new FileOutputStream(fileLocation);
bitmap.compress(CompressFormat.PNG, 100, stream);
What about “.bmp”, “.tiff”, “.gif” ??
It seems like CompressFormat only supports ‘CompressFormat.PNG’ and ‘CompressFormat.JPG’.
Is this limitation?
Yes Limited To JPG , PNG , WEBP
http://developer.android.com/reference/android/graphics/Bitmap.CompressFormat.html