我使用的是imageresizer,它在运行时运行得很好:
foreach (string fileKey in Request.Files.Keys)
{
//Skip unused file controls.
var file = Request.Files[fileKey];
if (file.ContentLength <= 0) continue;
//Get the physical path for the uploads folder and make sure it exists
string desFolder = Server.MapPath("~/Data/ProductImages/") + productId.ToString();
if (!Directory.Exists(desFolder)) Directory.CreateDirectory(desFolder);
//string fileName;
string guid = System.Guid.NewGuid().ToString();
//Generate each version
foreach (string suffix in versions.Keys)
{
//Generate a filename (GUIDs are best).
string filePath = Path.Combine(desFolder, guid + suffix);
//Let the image builder add the correct extension based on the output file type
ImageBuilder.Current.Build(file, filePath, new ResizeSettings(versions[suffix]), false, true);
}
但是从视觉工作室得到这个警告
ImageResizer.ImageBuilder.Build(对象,对象,Image Resizer.RizeSettings,bool,bool)'已过时:'Use.Build(new Image Job(source,dest、settings、dispose Source、add FileExtension)。最终路径而不是
如何修复?
解决方案是按照弃用警告的建议使用.Build(new Image Job(source, dest, settings, dispose Source, add FileExtension))
。
更换
ImageBuilder.Current.Build(file, filePath, new ResizeSettings(versions[suffix]), false, true);
带有
ImageBuilder.Current.Build(new ImageJob(file,filePath, new Instructions(versions[suffix]),false,true))