我有这个代码在用户选择后在图像按钮显示图像。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
我知道这一点。我不知道怎么做。 –