[英]Rotating image to Mobile's Orientation when capturing with camera :Android
我正在构建一个Android应用程序,从手机的相机中单击照片并将其显示在ImageView中,它会自动逆时针旋转90度。我想以手机单击的方向而不是手机的方向显示它让它旋转。
谁能提供相关的代码片段或一些相关文档的指针?
ExifInterface exif = new ExifInterface(imageFilePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
// rotate the image
break;
//....
}
使用这种方法将帮助您。
/*
* 1 = Horizontal (normal)
* 2 = Mirror horizontal
* 3 = Rotate 180
* 4 = Mirror vertical
* 5 = Mirror horizontal and rotate 270 CW
* 6 = Rotate 90 CW
* 7 = Mirror horizontal and rotate 90 CW
* 8 = Rotate 270 CW
*/
public static Bitmap getRotateBitmapImage(Bitmap bm, int newHeight,int newWidth, int exifOrientation) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
switch (exifOrientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
case ExifInterface.ORIENTATION_TRANSPOSE:
rotate = 45;
break;
case 0:
rotate = 360;
break;
default:
break;
}
matrix.postRotate(rotate);
// resizedBitmap = Bitmap.createScaledBitmap(bm, 65, 65, true);
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
return resizedBitmap;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.