.NET正确使用软件包

时间:2020-07-27 03:20:06

标签: c# .net .net-core

我尝试安装Magick.NET,,是使用从https://www.nuget.org/packages/Magick.NET-Q8-x64/获得的dotnet add package Magick.NET-Q8-x64 --version 7.21.1安装的

我尝试运行从https://stackoverflow.com/a/31829105/13924025获得的几行代码:

public string UploadFile(string fileName, IFormFile file)
    {
        string extension = System.IO.Path.GetExtension(file.FileName);
        string newFileName = "";
        if (fileName == null)
        {
            // newFileName = Guid.NewGuid ().ToString () + "-" + file.FileName;
            newFileName = Guid.NewGuid().ToString() + extension;
        }
        else
        {
            newFileName = Guid.NewGuid().ToString() + "-" + fileName + extension;
        }
        string filePath = "./Files/" + newFileName;

        using (MagickImage image = new MagickImage(file))
        {
          image.Scale(new Percentage(60));
          image.Write(filePath);
        }
        return newFileName;
    }

但是出现错误“找不到类型或名称空间名称'MagickImage'”。有解决这个问题的建议吗?

1 个答案:

答案 0 :(得分:1)

您需要在C#文件的开头添加using ImageMagick;