2011-10-31 75 views
2

我正在使用android中的自定義前置攝像頭拍照,但以錯誤的方向保存圖像。任何人都可以告訴我如何避免這種情況或如何旋轉圖像並將其保存在android的媒體商店?任何人都可以提供一個例子嗎?如何旋轉圖像並保存在Android的媒體商店

感謝

回答

5

要旋轉圖像:

Bitmap bmp = getOriginalBitmap(); 
Matrix rotateMatrix = new Matrix(); 
rotateMatrix.postRotate(degreeToRotate); 
Bitmap rotatedBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), rotateMatrix, false); 

那麼你應該能夠將其保存,像這樣:

MediaStore.Images.Media.insertImage(getContentResolver(), rotatedBitmap, "My bitmap", "My rotated bitmap"); 
0

您應該從EXIF data獲得取向,像這樣:

ExifInterface exif = new ExifInterface(sourceFileName);  //Since API Level 5 
String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION); 

同樣,您應該使用setAttribute()來更改方向。

+1

僅適用於JPEG格式;) – jclova

相關問題