如何解决当我尝试将图像转换为webp
我正在通过阅读this文章来学习如何将图像转换为.webp。 这是我打算执行的代码:
public IActionResult ConvertImage(IFormFile file)
{
var webpFullFilePath = Path.Combine(_webHostEnvironment.WebRootPath,"imagename.webp");
using (var webPFileStream = new FileStream(webpFullFilePath,FileMode.Create))
{
using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
{
imageFactory.Load(file.OpenReadStream()) // throws error here
.Format(new WebPFormat())
.Quality(100)
.Save(webPFileStream);
}
}
}
但是当我上传图片时,它会抛出异常:
System.TypeInitializationException:“ ImageProcessor.Plugins.WebP.Imaging.Formats.NativeMethods”的类型初始值设定项引发了异常。 ---> System.IO.IOException:文件'/home/alex/Documents/sayzim/api/bin/Debug/netcoreapp3.1/ImageProcessor.dll'已经存在。 在System.IO.FileSystem.CreateDirectory(String fullPath) 在System.IO.DirectoryInfo.Create() 在ImageProcessor.Configuration.NativeBinaryFactory处。 c__DisplayClass7_0.b__0(字符串b) 在System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey key,Func
2 valueFactory处) 在ImageProcessor.Configuration.NativeBinaryFactory.RegisterNativeBinary处(字符串名称,Byte [] resourceBytes) 在ImageProcessor.Plugins.WebP.Imaging.Formats.NativeMethods..cctor() ---内部异常堆栈跟踪结束---
这是我正在使用的软件包:
-
<PackageReference Include="ImageProcessor" Version="2.9.1" />
-
<PackageReference Include="ImageProcessor.Plugins.WebP" Version="1.3.0" />
-
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
如何解决此问题?如果您知道将图像转换为.webp的另一种方法,请与我分享:)
PS 。我使用的是Linux Mint。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。