简体   繁体   English

使用C#和元数据提取器从.tif文件读取元数据时引发异常

[英]Exception thrown when reading meta data from .tif file using c# and metadata extractor

I am trying to read the metadata from a .tif file using the Metadata Extractor dll and I keep getting a FileIsNotFoundException. 我正在尝试使用Metadata Extractor dll从.tif文件中读取元数据,并且不断收到FileIsNotFoundException。 It works fine when I try the same code using a .jpeg file. 当我使用.jpeg文件尝试相同的代码时,效果很好。

FileStream OriginalFile = new FileStream(FullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(OriginalFile);
foreach (var directory in directories)
    foreach (var tag in directory.Tags)
        Console.WriteLine($"{directory.Name} - {tag.Name} = {tag.Description}");

Edit : I re-installed the package and now have the XmpCore.dll inside the packages folder of my project but I still see the same exception as before. 编辑 :我重新安装了程序包,现在我的项目的程序包文件夹中有XmpCore.dll,但是我仍然看到与以前相同的异常。 Works fine for .jpeg and .psd files. 适用于.jpeg和.psd文件。

Exception thrown when trying open a .tiff image 尝试打开.tiff图像时引发异常

FileNotFoundException means that your FullPath doesn't contain a file that's actually on disk. FileNotFoundException意味着FullPath不包含磁盘上实际存在的文件。

Try adding: 尝试添加:

Console.WriteLine(FullPath);
Console.WriteLine(File.Exists(FullPath));

Also double check between .tif and .tiff. 还要仔细检查.tif和.tiff之间。

EDIT Your screenshot shows the missing file is XmpCore.dll . 编辑您的屏幕截图显示丢失的文件是XmpCore.dll When you added the NuGet reference to MetadataExtractor , you should also have picked up XmpCore . 当您将NuGet引用添加到MetadataExtractor ,您还应该已经选择了XmpCore

Here's an example of packages.config : 这是packages.config的例子:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="MetadataExtractor" version="1.5.3" targetFramework="net45" />
  <package id="SharpZipLib" version="0.86.0" targetFramework="net45" />
  <package id="XmpCore" version="1.2.2" targetFramework="net45" />
</packages>

Ensure you also have the relevant project references. 确保您还具有相关的项目参考。

After building a new .NET 4.5 console project with the above packages.config , the bin/Debug folder looked like this: 在使用上述packages.config构建新的.NET 4.5控制台项目之后, bin/Debug文件夹如下所示:

在此处输入图片说明

And the contents of the packages folder: packages文件夹的内容:

在此处输入图片说明

我通过将解决方案资源管理器中“引用”下的XmpCore的“复制本地”属性更改为True来解决了该异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM