Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 从MediaStore.Images.Media.DATA获取图像的方向大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个图像的MediaStore. Images.Media.DATA uri如何使用该uri@L_806_3@mediaStore.Images.Imagecolumns.ORIENTATION?我得到一个NullPointerException. @H_801_5@ @H_801_5@以下是我的代码,

@H_801_5@
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;
}
@H_801_5@我在cursor.moveToFirst()代码行中得到一个NullPointerException.

解决方法

使用此方法获取方向 @H_801_5@ @H_801_5@
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;
    }

大佬总结

以上是大佬教程为你收集整理的android – 从MediaStore.Images.Media.DATA获取图像的方向全部内容,希望文章能够帮你解决android – 从MediaStore.Images.Media.DATA获取图像的方向所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。