2014-01-30 72 views
0

當我在手機上拍攝照片時,使用Android應用無法正確旋轉圖像,無論我做什麼,它總是處於風景中。使用Android應用旋轉拍攝失敗 - 始終處於橫向佈局

這裏是我的代碼如何調用相機應用:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
intent.putExtra(MediaStore.EXTRA_OUTPUT, mPictureFileUri); 
startActivityForResult(intent, REQUEST_PHOTO); 

這裏是上ActivitiResult方法:

public void onActivityResult(int requestCode, int resultCode, Intent data){ 
    if(resultCode != Activity.RESULT_OK) 
     return; 
    if(requestCode == REQUEST_PHOTO){ 
     //here I show picture, but beside shove it, I need also rotate it. 
     //data are here null 
    } 
} 

回答

1

可以讀取圖片文件的EXIF和旋轉它正確編程:

Bitmap image = BitmapFactory.decodeFile(pictureFile.getAbsolutePath()); 

Matrix matrix = new Matrix(); 

ExifInterface exifInterface = new ExifInterface(pictureFile.getAbsolutePath()); 

int rotation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 
     ExifInterface.ORIENTATION_NORMAL); 
switch(rotation){ 
    case ExifInterface.ORIENTATION_NORMAL:{ 
    }break; 
    case ExifInterface.ORIENTATION_ROTATE_90:{ 
     matrix.postRotate(90); 
     image = Bitmap.createBitmap(image, 0, 0, image.getWidth(), image.getHeight(), 
       matrix, true); 
    }break; 
    case ExifInterface.ORIENTATION_ROTATE_180:{ 
     matrix.postRotate(180); 
     image = Bitmap.createBitmap(image, 0, 0, image.getWidth(), image.getHeight(), 
       matrix, true); 
    }break; 
    case ExifInterface.ORIENTATION_ROTATE_270:{ 
     matrix.postRotate(270); 
     image = Bitmap.createBitmap(image, 0, 0, image.getWidth(), image.getHeight(), 
       matrix, true); 
    }break; 
} 

// convert bitmap to jpeg with 50% compression 
image.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(pictureFile)); 
+0

我已更新我的帖子 –

+0

非常感謝:) – 5er

相關問題