三星 S 系列设备中的图像方向始终 returns 零
Image orientation always returns zero in Samsung S series devices
我创建了一个使用相机意图来捕捉照片的应用程序。照片被很好地捕获并保存到相应的文件夹中。问题是只有在三星 S 系列设备上,图像总是以纵向模式显示,即使图像是在横向模式下拍摄的。由于这个问题,我试图获取捕获图像的方向,然后相应地更改它们以符合我的要求,但方向总是 returns 零。
我正在尝试使用这个方法:
public static int getRotation(Context context,Uri selectedImage) {
int rotation =0;
ContentResolver content = context.getContentResolver();
Cursor mediaCursor = content.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[] { "orientation", "date_added" },null, null,"date_added desc");
if (mediaCursor != null && mediaCursor.getCount() !=0 ) {
while(mediaCursor.moveToNext()){
rotation = mediaCursor.getInt(0);
break;
}
}
mediaCursor.close();
return rotation;
}
无论图像的方向如何,该方法总是returns 0。我哪里错了?如何解决这个问题?
三星喜欢砸东西。我以前也有过类似的经历。
但是相机意图应该在 jpg 文件中将方向信息保存为 Exif。
当您使用相机 Intent 时,您应该有文件 Uri。然后你可以使用 ExifInterface
直接从文件中添加旋转。
http://developer.android.com/reference/android/media/ExifInterface.html
示例代码
ExifInterface exif = new ExifInterface(file);
int oridentation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
//do what you want
break;
case ExifInterface.ORIENTATION_ROTATE_180:
//do what you want
break;
....
}
我创建了一个使用相机意图来捕捉照片的应用程序。照片被很好地捕获并保存到相应的文件夹中。问题是只有在三星 S 系列设备上,图像总是以纵向模式显示,即使图像是在横向模式下拍摄的。由于这个问题,我试图获取捕获图像的方向,然后相应地更改它们以符合我的要求,但方向总是 returns 零。
我正在尝试使用这个方法:
public static int getRotation(Context context,Uri selectedImage) {
int rotation =0;
ContentResolver content = context.getContentResolver();
Cursor mediaCursor = content.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[] { "orientation", "date_added" },null, null,"date_added desc");
if (mediaCursor != null && mediaCursor.getCount() !=0 ) {
while(mediaCursor.moveToNext()){
rotation = mediaCursor.getInt(0);
break;
}
}
mediaCursor.close();
return rotation;
}
无论图像的方向如何,该方法总是returns 0。我哪里错了?如何解决这个问题?
三星喜欢砸东西。我以前也有过类似的经历。
但是相机意图应该在 jpg 文件中将方向信息保存为 Exif。
当您使用相机 Intent 时,您应该有文件 Uri。然后你可以使用 ExifInterface
直接从文件中添加旋转。
http://developer.android.com/reference/android/media/ExifInterface.html
示例代码
ExifInterface exif = new ExifInterface(file);
int oridentation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
//do what you want
break;
case ExifInterface.ORIENTATION_ROTATE_180:
//do what you want
break;
....
}