Android Rotate Picture Before Saving
I just finished my camera activity and it's wonderfully saving the data. What I do after the picture is taken: protected void savePictureData() { try { FileOutputStream
Solution 1:
Read the path from sd card and paste the following code...It'll Replace the existing photo after rotating it..
Note: Exif doesn't work on most of the devices, it returns incorrect data so it's good to hard code the rotation before saving to any degree you want to, Just change the angle value in postRotate.
Stringphotopath= tempphoto.getPath().toString();
Bitmapbmp= BitmapFactory.decodeFile(photopath);
Matrixmatrix=newMatrix();
matrix.postRotate(90);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
FileOutputStream fOut;
try {
fOut = newFileOutputStream(tempphoto);
bmp.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Solution 2:
Before you create your FileOutputStream
you can create a new Bitmap
from the original that has been transformed using a Matrix
. To do that you would use this method:
createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, booleanfilter)
Where the m
defines a matrix that will transpose your original bitmap.
For an example on how to do this look at this question: Android: How to rotate a bitmap on a center point
Solution 3:
bitmap = RotateBitmap(bitmap, 90);
publicstatic Bitmap RotateBitmap(Bitmap source, float angle)
{
Matrixmatrix=newMatrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
Post a Comment for "Android Rotate Picture Before Saving"