3 回答
TA贡献1993条经验 获得超5个赞
好的,大家好,这个错误似乎不会在一段时间内得到修复。尽管我找到了一种实现ExifInformation的方法,以便使两个设备(具有正确的Exif标签和不正确的exif标签的设备一起使用)。
因此,问题出在某些(较新的)设备上,存在一个错误,该错误使拍摄的照片没有适当的exif标签就被保存在您的应用文件夹中,而正确旋转的图像被保存在android默认文件夹中(即使不应该)。 。
现在我要做的是,我记录从应用程序启动相机应用程序的时间。关于活动结果,我查询媒体提供者以查看是否保存了此时间戳后是否保存了任何图片。这意味着,最有可能的操作系统将正确旋转的图片保存在默认文件夹中,并且当然在媒体存储中放置了一个条目,我们可以使用此行中的旋转信息。现在,确保我们正在查看正确的图像,我将该文件的大小与我可以访问的文件大小进行比较(保存在我自己的应用程序文件夹中);
int rotation =-1;
long fileSize = new File(filePath).length();
Cursor mediaCursor = content.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.MediaColumns.SIZE }, MediaStore.MediaColumns.DATE_ADDED + ">=?", new String[]{String.valueOf(captureTime/1000 - 1)}, MediaStore.MediaColumns.DATE_ADDED + " desc");
if (mediaCursor != null && captureTime != 0 && mediaCursor.getCount() !=0 ) {
while(mediaCursor.moveToNext()){
long size = mediaCursor.getLong(1);
//Extra check to make sure that we are getting the orientation from the proper file
if(size == fileSize){
rotation = mediaCursor.getInt(0);
break;
}
}
}
现在,如果此时的旋转度仍为-1,则意味着这是具有正确旋转信息的手机之一。此时,我们可以对返回到onActivityResult的文件使用常规exif方向
else if(rotation == -1){
rotation = getExifOrientationAttribute(filePath);
}
您可以轻松地找出如何找到EXIF方向想在这个问题的答案在Android相机定位问题
还要注意,只有在Api 5级之后才支持ExifInterface。因此,如果您想在2.0之前支持电话,则可以使用我为Drew Noakes提供的Java便利库。http://www.drewnoakes.com/code/exif/
祝您的图片旋转愉快!
编辑:因为有人问,我用过的意图以及我的开始方式是这样的
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//mediaFile is where the image will be saved
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mediaFile));
startActivityForResult(intent, 1);
TA贡献1809条经验 获得超8个赞
您也可以这样:
Matrix matrix = new Matrix();
// rotate the Bitmap (there a problem with exif so we'll query the mediaStore for orientation
Cursor cursor = getApplicationContext().getContentResolver().query(selectedImage,
new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
if (cursor.getCount() == 1) {
cursor.moveToFirst();
int orientation = cursor.getInt(0);
matrix.preRotate(orientation);
}
- 3 回答
- 0 关注
- 1151 浏览
添加回答
举报