从MediaStore.Images.Media.DATA获得图象的方向 [英] get orientation of image from MediaStore.Images.Media.DATA
本文介绍了从MediaStore.Images.Media.DATA获得图象的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有MediaStore.Images.Media.DATA的URI的图像我怎么能使用URI得到MediaStore.Images.ImageColumns.ORIENTATION?我得到一个NullPointerException异常。
i have MediaStore.Images.Media.DATA uri for an image how I can get MediaStore.Images.ImageColumns.ORIENTATION using that uri ? I am getting a NullPointerException.
以下是我的code,
private int getOrientation(Context context, Uri photoUri) {
Log.v("orientatioon", "not crashed01");
Cursor cursor = context.getContentResolver().query(photoUri,
new String[] { MediaStore.Images.ImageColumns._ID,MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
Log.v("orientatioon", "not crashed02");
cursor.moveToFirst();
Log.v("orientatioon", "not crashed 03");
int i=cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.ORIENTATION));
Log.v("orientatioon", ""+i);
cursor.close();
return i;
}
我收到code的 NullPointerException异常
在cursor.moveToFirst()行。
I am getting a NullPointerException
at cursor.moveToFirst() line of code.
推荐答案
使用此法
来获得的定位
public static int getExifOrientation(String filepath) {// YOUR MEDIA PATH AS STRING
int degree = 0;
ExifInterface exif = null;
try {
exif = new ExifInterface(filepath);
} catch (IOException ex) {
ex.printStackTrace();
}
if (exif != null) {
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
if (orientation != -1) {
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270;
break;
}
}
}
return degree;
}
这篇关于从MediaStore.Images.Media.DATA获得图象的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文