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

限于喜欢 提交于 2020-01-04 13:42:31

问题


I'm using imageresizer, it works very well at run time:

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); 
                }

but get this warning from visual studio

ImageResizer.ImageBuilder.Build(object, object, Image Resizer.Resize Settings, bool, bool)' is obsolete: 'Use .Build(new Image Job(source, dest, settings, dispose Source, add FileExtension)).Final Path instead'

how fix it?


回答1:


The solution is to use .Build(new Image Job(source, dest, settings, dispose Source, add FileExtension)) as the deprecation warning suggests.

Replace

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

with

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


来源:https://stackoverflow.com/questions/20325525/imageresizer-use-buildnew-image-jobsource-dest-settings-dispose-source-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!