2012-10-29 24 views
5

我正在處理我的應用程序中的相機圖像,實際上得到的是urls.The相機應用程序是在肖像模式。所以圖像有時左旋或右旋轉。我知道我們可以使用EXIF正常圖像方向從畫廊,那裏,我們可以查看EXIF值,並做適當的changes.Basicaly這是EXIF如何應用EXIF方向的圖像作爲網址android

ExifInterface exif = new ExifInterface("filepath"); 
exif.getAttribute(ExifInterface.TAG_ORIENTATION); 

代碼所以我的問題是什麼東西在我的情況的文件路徑,是它的url本身或應該我創建一個文件.. 任何幫助將不勝感激....

回答

1

首先,你必須得到Uri在活動結果,像這裏 Get image Uri in onActivityResult after taking photo?
然後,當你有Uri時,你可以得到像這樣的文件路徑: String filepath = getRealPathFromURI(someUri);

public String getRealPathFromURI(Uri contentUri) { 
    String res = null; 
    String[] proj = { MediaStore.Images.Media.DATA }; 
    Cursor cursor = getContentResolver().query(contentUri, proj, null, null, null); 
    if(cursor != null && cursor.moveToFirst()){; 
     int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
     res = cursor.getString(column_index); 
    } 
    cursor.close(); 
    return res; 
} 


然後,如果filepath不爲空且不爲空,則可以獲取EXIF數據,檢查它並在需要時旋轉圖像。
希望它會有所幫助。

+0

如何應用EXIF方向? – NarendraJi

+0

你必須得到方向,如: int pictureOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL); 然後,你必須檢查一下:如果 (pictureOrientation == ExifInterface.ORIENTATION_ROTATE_180){...在這裏做你的輪換代碼} 你要檢查其他ExifInterface.ORIENTATION_ * PARAMS爲好。 – Evgen

+0

好的,thnx的答覆 – NarendraJi

相關問題