Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ExiFinInterface_JNI:未检测到原始图像错误_Android - Fatal编程技术网

Android ExiFinInterface_JNI:未检测到原始图像错误

Android ExiFinInterface_JNI:未检测到原始图像错误,android,Android,在尝试获取ExiFinInterface时,我一直看到未检测到的原始图像错误消息 ExifInterface exifInterface = new ExifInterface(filepath); int rotation=exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_UNDEFINED); 有人知道这是什么原因吗 我从Uri获取它,但我知道文件路径存在 这些说法

在尝试获取ExiFinInterface时,我一直看到未检测到的原始图像错误消息

ExifInterface exifInterface = new ExifInterface(filepath); 
int rotation=exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_UNDEFINED); 
有人知道这是什么原因吗

我从Uri获取它,但我知道文件路径存在

这些说法相互矛盾A
Uri
不是文件。如果
Uri
的方案是
file
,那么并且只有这样才能通过
getPath()
获得文件的文件系统路径。如果该方案是其他方案,例如
内容
,则无法获得文件系统路径,因为不要求有文件。例如,
Uri
http://stackoverflow.com/questions/42930509/exifinterface-jni-raw-image-not-detected-error
并不意味着Android设备在
/questions/42930509/exifinterface jni raw image not detected error
上有一个文件


来自
com.android.support的
ExiFinInterface
(例如,当前最新版本为25.3.0)已安装。创建
ContentResolver
(通过
getContentResolver()
上下文上创建
ContentResolver,例如您的
活动
)。在该
ContentResolver
上调用
openInputStream()
,提供
Uri
(适用于
文件
内容
方案)。将该
InputStream
传递给库的
ExifInterface
构造函数。这同时确保您不会给用户带来安全问题,也避免了为要检查的内容获取文件系统路径的问题。

长话短说,请将以下示例应用于您的代码:

Uri uri = Uri.fromFile(f); 
// where f of type File 
in = context.getApplicationContext().getContentResolver().openInputStream(uri);
// context should refer to your context app
ExifInterface exifInterface = new ExifInterface(in);
// you'll need "exifInterface" 
别忘了关闭输入流

in.close();

您收到关于JNI的错误消息这一事实表明您正在使用。请考虑使用或。除此之外,
filepath
的值是多少?您是从哪里获得的?@commonware我是从Uri获得的,但我知道filepath存在。我在哪里可以获得不同版本的ExiFinInterface?我使用的是Android support-v4:25.3.0,尽管我不确定ExiFinInterface实现是否来自于此(我对Android开发相对较新),但我通过调用getPath()从Uri获得它我还创建了一个file对象,并测试了该文件是否存在,返回true。我们有一个min SDK版本19,因此我无法使用ExiFinInterface(InputStream)构造函数。你知道解决这个问题的方法吗?@JohnKane:“我无法使用ExifInterface(InputStream)构造函数”——是的,你知道。你把
android.media.ExifInterface
(内置的一个,任何人都不应该使用)和
android.support.media.ExifInterface
(我在回答中引用的库中的一个)混淆了。将
compile'com.support.android:exifinterface:25.3.0'
添加到您的
dependencies
闭包中,以及
support-v4:25.3.0
依赖项。然后,使用android.support.media.ExifInterface
。谢谢,我在依赖项中添加了这一行,但是,当我尝试读取属性exif.getAttributeInt(ExifInterface.TAG\u orientation,ExifInterface.orientation\u UNDEFINED)时,无论手机的方向如何,我仍然会得到一个0的方向@约翰肯:也许图像没有方向标签。如果它是JPEG,请从设备下载并使用适当的工具(例如,Linux中的
exif
命令)检查它是否有标签。如果它不是JPEG,则可能没有任何EXIF头可供使用。