问题描述
我想从图库中拍照并正确旋转显示。 经过大量搜索之后,我想出了一个解决方案,很不幸,该解决方案对我不起作用,并且轮换是错误的。 我的这种方法总是返回零。 为了方便起见,我总结了代码
从图库中捕获图像:
authentication-service
Intent pickPhoto = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto,1)
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
super.onActivityResult(requestCode,resultCode,data);
switch (requestCode) {
case 1:
if (resultCode == RESULT_OK) {
Uri selectedImage = data.getData();
// imgProfile.setImageURI(selectedImage);
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),selectedImage);
imgProfile.setImageBitmap(modifyOrientation(bitmap,data.getData().getPath()));
} catch (IOException e) {
e.printStackTrace();
}
}
break;
}
}
public static Bitmap modifyOrientation(Bitmap bitmap,String image_absolute_path) throws IOException {
ExifInterface ei = new ExifInterface(image_absolute_path);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_UNDEFINED);
Log.i("TESTETS","" + orientation);
Bitmap rotatedBitmap = null;
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotatedBitmap = rotateImage(bitmap,90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotatedBitmap = rotateImage(bitmap,180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotatedBitmap = rotateImage(bitmap,270);
break;
case ExifInterface.ORIENTATION_NORMAL:
default:
rotatedBitmap = bitmap;
}
Log.i("TESTETS","rotated" + rotatedBitmap);
return rotatedBitmap;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)