我有這個代碼在用戶選擇後在圖像按鈕顯示圖像。android - 圖片旋轉在圖像按鈕
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
Uri selectedImageUri = data.getData();
if (null != selectedImageUri) {
// Set the image in ImageView
_changePicture.setImageURI(selectedImageUri);
}
}
我的問題是,當選擇一個大圖像時,它會顯示左旋90度。我在這裏找到了一些解決方案在stackoverflow.com,但我不能使用它們中的任何一個,因爲它們使用「圖像」,而我只使用「Uri」。
編輯: 使用代碼像這樣的:
public static void rotateImageIfRequired(Uri selectedImage) throws IOException {
ExifInterface ei = new ExifInterface(selectedImage.getPath());
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
Log.e(TAG,"ROTATE = 90");
case ExifInterface.ORIENTATION_ROTATE_180:
Log.e(TAG,"ROTATE = 180");
//return rotateImage(img, 180);
case ExifInterface.ORIENTATION_ROTATE_270:
Log.e(TAG,"ROTATE = 270");
//return rotateImage(img, 270);
default:
Log.e(TAG,"ROTATE = 0");
//return img;
}
}
「ROTATE = 0」 被返回。一些圖像是幾天前拍攝的。他們都很大。在小圖像中不發生旋轉。
其分毫用imagebutton做。我假設你正在從相機中獲取圖片?您需要以您想要的方向請求它,或者自己手動旋轉並重新保存它 – Blundell
我知道這一點。我不知道怎麼做。 –