我有以下用于研究图像方向的简单代码。
Cursor cursor = getContentResolver().query(photoUri,
new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
当photoUri是内容uri时,即从content://开始,则可以很好地检索光标。当我从图库中选择图像时,我得到一个contentUri。
但是,当photoUri是fileUri时,即从file://a/b/c.jpg开始(当我从相机捕获图像时会发生这种情况),光标为null。
是什么赋予了 ?我对这种情况真的很困惑。
回答评论:
你不能 MediaStore.Images.ImageColumns.ORIENTATION
是存储在content://
数据库中的数据库列。该file://
数据库不包含这样的列,所以你不能查询。
回答问题:
要提取方向,android具有本机ExifInterface
类:https : //developer.android.com/reference/android/media/ExifInterface.html
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句