2012-01-14 144 views
12

我正在使用我的Samsung Galaxy SII設備拍攝照片。 保存並在屏幕上顯示後,我看到它旋轉了90度。Android將照片旋轉90度(由相機拍攝)

我知道這是一些設備問題 - 它不會發生在所有設備上。

我正在拍攝照片,使用給定的照相機意圖並將其保存在onActivityResult函數中。

我環顧四周,但沒有找到一個堅實的解決方案。

任何想法如何找到問題,並將其僅旋轉回「有問題的」設備?

回答

8

這是一個基於不同製造商設置的錯誤。有些手機旋轉它們,有些則不旋轉。看到該鏈接,這是問題#1193

http://code.google.com/p/android/issues/detail?id=1193

+0

因此,據我所見 - 我必須從相機請求橫向模式?有沒有辦法找出某種程度上應用程序運行的設備是否在處理它?或者我應該讓所有設備都使用橫向模式並遮擋肖像(這不是一個很好的解決方案) – user1136875 2012-01-15 07:27:49

+1

我自己還沒弄清楚那一部分。我個人會嘗試http://developer.android.com/guide/topics/media/camera.html#custom-camera,看看是否有所作爲。 – 2012-01-15 07:32:25

+0

如果你想知道 - 請讓我知道:) – user1136875 2012-01-15 14:06:12

-2

我想這可能是您的方向傳感器的問題..您是否在您的程序中處理傳感器值..要知道用戶何時拍攝照片時設備處於水平或垂直方向..

+2

不能依靠它 - 因爲它工作在某些設備上良好,而不是其他 – user1136875 2012-01-14 20:43:06

4

通道中,從相機捕獲的文件路徑

public Bitmap rotateBitmapOrientation(String photoFilePath) { 

    // Create and configure BitmapFactory 
    BitmapFactory.Options bounds = new BitmapFactory.Options(); 
    bounds.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(file, bounds); 
    BitmapFactory.Options opts = new BitmapFactory.Options(); 
    Bitmap bm = BitmapFactory.decodeFile(file, opts); 
    // Read EXIF Data 
    ExifInterface exif = new ExifInterface(file); 
    String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION); 
    int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL; 
    int rotationAngle = 0; 
    if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90; 
    if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180; 
    if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270; 
    // Rotate Bitmap 
    Matrix matrix = new Matrix(); 
    matrix.setRotate(rotationAngle, (float) bm.getWidth()/2, (float) bm.getHeight()/2); 
    Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bounds.outWidth, bounds.outHeight, matrix, true); 
    // Return result 
    return rotatedBitmap; 
} 
相關問題