问题
Capture by My Camera App and Open image by Galerry: My code open:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(dt.FileName);
intent.setDataAndType(Uri.fromFile(file), "image/*");
startActivity(intent);
Capture by Standard Camera and Open image by Galerry:
I check Original Image is the same. How rotate image when open image by Gallery the same Standard Camera?
回答1:
Use this code to change the image orientation
ExifInterface exif = new ExifInterface(filepath);
int exifOrientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int rotate = 0;
switch (exifOrientation)
{
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
}
if (rotate != 0)
{
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix mtx = new Matrix();
mtx.preRotate(rotate);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
}
来源:https://stackoverflow.com/questions/22905768/how-rotate-image-when-open-image-by-gallery