【发布时间】:2022-01-20 20:00:24
【问题描述】:
我在打开 jpg 文件时遇到问题。这是我开始使用的代码:
var image = await Image.LoadAsync("sample.jpg")
这产生了异常:
An exception of type 'SixLabors.ImageSharp.UnknownImageFormatException' occurred in System.Private.CoreLib.dll but was not handled in user code
Image cannot be loaded. Available decoders:
- PNG : PngDecoder
- GIF : GifDecoder
- BMP : BmpDecoder
- TGA : TgaDecoder
- JPEG : JpegDecoder
为了确定文件未被识别为 jpeg 的原因,我使用了以下代码:
using (var stream = File.OpenRead("sample.jpg"))
{
var jpegDecoder = new JpegDecoder();
jpegDecoder.Decode(Configuration.Default, stream);
}
这给了我以下例外:
An unhandled exception of type 'SixLabors.ImageSharp.InvalidImageContentException' occurred in SixLabors.ImageSharp.dll
Missing SOI marker.
我倾向于认为所涉及的图像存在问题,但我可以在 Windows 照片查看器和 Google Chrome 中查看它。如何确定文件有什么问题?
编辑:
感谢@user9938,我能够确定这是一个 RIFF 或 WEBPV8 文件:
有没有 ImageSharp 的 riff 插件?
【问题讨论】:
标签: c# jpeg imagesharp