使用 System.Drawing.Imaging; System.Drawing 中不存在成像

using System.Drawing.Imaging; Imaging does not exist in the System.Drawing

我正在尝试使用此库从 .Net Core 应用程序中的照片中提取元数据:

https://www.codeproject.com/Articles/27242/ExifTagCollection-An-EXIF-metadata-extraction-libr

然而,在实施 ExifTagCollection 时 class 我收到标题中列出的错误。

我已成功引用 System.Drawing 但它无法识别其绘图扩展名。任何帮助都会很棒。也愿意接受其他图书馆的建议,以实现我的目标。谢谢

如果您查看 microsoft 的站点,您会看到:

"Classes within the System.Drawing.Imaging namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions."

您正在使用 ASP.net 创建 Web 应用程序,因此您的项目不支持此 class

正如@TimonPost 所说,您不能使用 ASP.NET 中的命名空间,因为它依赖于交互式会话(这就是为什么它也无法在 Windows 服务中使用) .

如果您只是想要一种从在 ASP.NET Core 中工作的图像访问元数据的简单方法,请查看我的 MetadataExtractor 库。

https://github.com/drewnoakes/metadata-extractor-dotnet

如果您正在寻找 .NET Core 上的 System.Drawing 相关功能,您应该能够使用 System.Drawing.Common.

它在 .NET Core 上提供 System.Drawing API,并在 Windows、Linux 和 macOS 上运行。

如果您使用的是 Linux 和 macOS,则需要安装 libgdiplus 才能正常工作。要在 macOS 上安装 libgdiplus,运行 brew install mono-libgdiplus;在 Linux 上,您应该可以使用包管理器安装 libgdiplus 包。希望此部署将来会变得更容易。

它目前作为 System.Drawing.Common 包在 NuGet 上处于预览状态。

从长远来看,您可能需要考虑迁移到其他库,例如 ImageSharp。