当我尝试将图像转换为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() ---内部异常堆栈跟踪结束---

这是我正在使用的软件包:

  1. <PackageReference Include="ImageProcessor" Version="2.9.1" />
  2. <PackageReference Include="ImageProcessor.Plugins.WebP" Version="1.3.0" />
  3. <PackageReference Include="System.Drawing.Common" Version="4.7.0" />

如何解决此问题?如果您知道将图像转换为.webp的另一种方法,请与我分享:)

PS 。我使用的是Linux Mint。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...