以下是我的代码,
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);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;}
我在cursor.movetoFirst()代码行中得到一个NullPointerException.
@H_403_4@解决方法 使用此方法获取方向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; }@H_403_4@ @H_403_4@ @H_403_4@ @H_403_4@ 总结
以上是内存溢出为你收集整理的android – 从MediaStore.Images.Media.DATA获取图像的方向全部内容,希望文章能够帮你解决android – 从MediaStore.Images.Media.DATA获取图像的方向所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)