2014-03-02 149 views
0

我正在編寫一個依賴用戶定期拍照的Android應用。已經有文件證明,如果從前置攝像頭拍攝照片,則Android將返回翻轉的圖像,其旋轉90度。發生這種情況時,我可以成功調整圖片的方向。問題是我不知道是什麼時候使用前置攝像頭。通過了解在拍攝照片時使用前置攝像頭的時間,我可以確定是否應該重新定位它。確定Android攝像頭活動使用的攝像頭

有沒有什麼辦法可以確定,最好在onActivityResult()期間使用哪臺相機?是否有另一種練習用於幫助確定和修復圖片方向?

這是我的Camera活動啓動代碼。很直白:

private void startCameraIntent(String name) { 
    try { 
     String fileName = MontageConstants.APP_DATA_FOLDER + "/" + name + "/" + new Date().getTime() + ".jpg"; 
     Uri fileUri = Uri.fromFile(new File(fileName)); 

     Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
     takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); 
     startActivityForResult(takePictureIntent, TAKE_PIC_ACTIVITY_REQUEST_CODE); 
    } catch (Exception ex) { 
     Toast.makeText(this, "Couldn't take picture", Toast.LENGTH_LONG).show(); 
    } 
} 

謝謝!

+1

見我的回答是:http://stackoverflow.com/questions/22120421/how-to-rotate-android-device-camera-previewlibgdx/22120629#22120629 也許會對你有所幫助。 –

+0

這讓我失去了我需要的確切路徑。非常感謝你! –

回答

1

感謝Navjot Singh--我發現了我在他發佈的答案中需要的信息:How to rotate android device camera preview(libgdx)。實際上,您可以使用類ExifInterface讀取存儲的JPEG文件中的Exif標籤。由於我在操縱它們之前將圖片存儲到文件中,因此我只是插入文件路徑,獲取了方向,並進行了相應的旋轉/調整。

  ExifInterface ei = new ExifInterface(fileName); 
      orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);