Android 在纵向模式下拍照时图像旋转
我已经实现了一个自定义相机,我可以从中拍摄照片,保存照片,然后将其插入媒体存储并立即显示。我一直受到保存图像方向问题的困扰,我已经尝试使用ExiFinInterface直接使用文件路径或使用Android图像内容提供商提供的方向来修复此问题 方向始终返回为0。我已使用: 编辑: 在横向模式下拍照时,输出图像显示正确,但在纵向模式下拍照时,输出图像返回旋转图像(90度)。Android 在纵向模式下拍照时图像旋转,android,camera,uiimageorientation,Android,Camera,Uiimageorientation,我已经实现了一个自定义相机,我可以从中拍摄照片,保存照片,然后将其插入媒体存储并立即显示。我一直受到保存图像方向问题的困扰,我已经尝试使用ExiFinInterface直接使用文件路径或使用Android图像内容提供商提供的方向来修复此问题 方向始终返回为0。我已使用: 编辑: 在横向模式下拍照时,输出图像显示正确,但在纵向模式下拍照时,输出图像返回旋转图像(90度)。 我目前正在使用基于EXIF的方法。请确保您要传递的路径名开头没有“file://”。ExiFinInterface不会抛出错
我目前正在使用基于EXIF的方法。请确保您要传递的路径名开头没有“file://”。ExiFinInterface不会抛出错误或任何东西如果路径的前缀是错误或任何东西,则每次都会返回方向的默认值 确保要传递的路径名开头没有“file://”。ExiFinInterface不会抛出错误或任何东西如果路径的前缀是错误或任何东西,则每次都会返回方向的默认值 有日志告诉我们正确的方向吗?有日志告诉我们正确的方向吗?
private int getExifOrientation(String pathName)
{
//for complete info on EXIF orientation visit: http://sylvana.net/jpegcrop/exif_orientation.html
ExifInterface exif=null;
try {
exif = new ExifInterface(pathName);
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("ImagePreviewActivity", "Exif data of the image could not be retreived");
}
int orientation=exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
return orientation;
}
private int getRotation(int orientation)
{
int rotation=0;
switch(orientation)
{
case ExifInterface.ORIENTATION_ROTATE_90:
//orientation values is 6
rotation=90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
//orientation value is 3
rotation=180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
//orientation value is 8
rotation=270;
break;
case -1:
Log.d("ImagePreviewActivity","Error getting orientation from Exif data.");
break;
case 1:
Log.d("ImagePreviewActivity", "Image is properly oriented");
default:
Log.d("ImagePreviewActivity", "The value of orientation is "+orientation);
}
return rotation;
}
private Bitmap rotateBitmap(String pathName,int rotation)
{
Bitmap bmp=BitmapFactory.decodeFile(pathName);
Matrix matrix=new Matrix();
matrix.postRotate(90);
//start from x=0,y=0 and filter=false
Bitmap rotatedBitmap=Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix,false);
return rotatedBitmap;
}