C# - 使用 ImageResizer 调整和裁剪图像

C# - resizing and cropping images using ImageResizer

代码

ResizeSettings resizeCropSettings = new ResizeSettings("width=100&height=150&format=jpg&crop=auto");

         string fileName = ImageBuilder.Current.Build(file, newFile, resizeCropSettings, false, true);

消息说使用:

.Build(new ImageJob(source, dest, settings, disposeSource, addFileExtention)).FinalPath instead.

谁能解释一下这是什么意思?请给我一个例子。

消息已经很清楚了,这意味着你需要更换

...Build(file, newFile, resizeCropSettings, false, true);

var lImageJob = new ImageJob(...);

...Build(lImageJob);

看这里:ImageResizer 'Use .Build(new Image Job(source, dest, settings, dispose Source, add FileExtension)).Final Path instead'

检查您使用的是哪个版本。

替换

ImageBuilder.Current.Build(file, filePath, new ResizeSettings(versions[suffix]), false, true); 

ImageBuilder.Current.Build(new ImageJob(file,filePath, new Instructions(versions[suffix]),false,true))

如果

,您将收到评论中描述的错误

原因

You didn’t install the assembly specified in the error.
Your DLL depend on other DLL’s to get its job done and if you didn’t copy or install those too, you’d indeed get this error message.
Or you have installed an older version of the assembly.
This error occurs often when we use C# HelperClass to support the orchestrations, but can occur in other situations.

解决方案

Make sure that you have the last version of the assembly installed.

Rebuild the solution.
Deploy the correct solution.