portrait
还是landscape
我从code下面获得的路径为
/storage/emulated/0/DCIM/Camera/IMG_20181110_211757.jpg
然后我正在使用ExifInterface查找方向:
public static void getCameraPhotoOrientation(Activity activity, String imagePath) {
String path =getPath(activity,imagePath);
try {
ExifInterface ei = new ExifInterface(path);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
Timber.d("Type-1");
break;
case ExifInterface.ORIENTATION_ROTATE_180:
Timber.d("Type-2");
break;
case ExifInterface.ORIENTATION_ROTATE_90:
Timber.d("Type-3");
break;
case ExifInterface.ORIENTATION_UNDEFINED:
Timber.d("Type-4");
break;
}
}catch (IOException ex){
ex.printStackTrace();
}
}
我总是以ExifInterface.ORIENTATION_UNDEFINED
的身分
如何解决这个问题
答案 0 :(得分:2)
我的图库中有一张从相机拍摄的图像
除非开发者是该相机应用程序的作者,否则开发人员无法保证任何特定图像均来自该相机应用程序。
我试图找出图像是纵向还是横向
不需要图像为纵向或横向。例如,相机应用可能会将其照片裁剪为圆形或正方形。
我有从下面的代码获得的路径
在许多设备上,这些代码将因许多Uri
值而失败。如果您想将ExifInterface
用于Uri
,请使用getContentResolver().openInputStream()
在InputStream
所标识的内容上获取Uri
,然后传递该{{1 }}到this ExifInterface
constructor。
我总是以ExifInterface.ORIENTATION_UNDEFINED作为方向
图像不必具有EXIF标头,更不用说InputStream
。
如果该标签不存在,则可以检查图像的宽度和高度并进行猜测:
对于正方形图像,这将失败,而对于裁切图像,则将失败(例如,照片是纵向拍摄的,但用户将其裁切成宽度现在大于高度)。
最好的解决方案是更改您的应用,以不关心图像是纵向还是横向。最好的解决方案是询问用户如何处理图像,也许您可以使用上述算法在其中设置默认选项。
答案 1 :(得分:0)
通过如下更改路径访问过程来尝试
var results=data.d.results;
displayObjectProperty("getData",results,"Title");
function displayObjectProperty(id,object,Property){
for(var x in object)
{
if(typeof(object[x]) == "object"){displayObjectProperty(id,object[x],Property)}else{
if(x==Property){
document.getElementById(id).innerHTML += "<b>" + x + "</b>"+"::<i>" + object[x] + "</i>";
}
}
}
}