问题
I've been evaluating Nathanael Jones amazing imaging library and plugins for some image processing services my company is building on Azure. Before acquiring a license we are testing them fully to ensure they fit in within our scenario. Do yourself a favor and check them out Here.
I'm having great success with the plugins when using them in an ASP.NET MVC web application. I'm using the Image Server functionality within a Controller that I post to from the UI. Cropping, Resizing and Simple/Advanced filters are working as expected.
The problems I am having is when I move this functionality to a WCF service as a class library within that application. The cropping and resizing work exactly as expected, however all the filtering instructions (brightness, contrast, sepia, etc...) are either being ignored or fail silently. Here is the image processing code:
var instructions = new ImageResizer.Instructions();
//All of these instructions work
instructions.Width = 300;
instructions.Height = 300;
instructions.Mode = ImageResizer.FitMode.Crop;
instructions.OutputFormat = ImageResizer.OutputFormat.Jpeg;
instructions.JpegQuality = 90;
double[] cropCoordinates = {0,100,0,100};
instructions.CropRectangle = cropCoordinates;
instructions.Mode = ImageResizer.FitMode.Crop;
//These instructions are ignored, or fail silently
instructions.Invert = true;
instructions.Saturation = -1;
instructions.Sepia = true;
var imageJob = new ImageResizer.ImageJob();
imageJob.Instructions = instructions;
imageJob.Source = bmpSource;
imageJob.Dest = typeof(Bitmap);
imageJob.Build();
I've duplicated the Web.Config settings that my MVC application used to the App.Config of the class library that is using the ImageResizing packages (from Nuget).
<configuration>
<configSections>
<section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false" />
</configSections>
<resizer>
<plugins>
<add name="SimpleFilters" />
<add name="AdvancedFilters" />
</plugins>
</resizer>
</configuration>
And just to be sure, I've also included using statements for the main library as well as for the plugins:
using ImageResizer;
using ImageResizer.Plugins.AdvancedFilters;
using ImageResizer.Plugins.SimpleFilters;
As I mentioned, the cropping and resizing work perfectly when moved to a class library with a WCF service, but the filters are failing silently. The images are cropped and sized as instructed, but the filters are not applied to the images. I've tried several variations on installing the libraries (even including the packages on every project within my solution).
Could the fact that my WCF service is hosted as a NET.TCP Endpoint? Should I consider updating my architecture to have the imaging services powered via a Web API that the WCF service posts to?
Updated
I'm bypassing Web.Config/App.Config by installing plugins in code like so:
ImageResizer.Configuration.Config.Current.Plugins.Install(new ImageResizer.Plugins.SimpleFilters.SimpleFilters());
ImageResizer.Configuration.Config.Current.Plugins.Install(new ImageResizer.Plugins.AdvancedFilters.AdvancedFilters());
I've verified that plugins are now loaded within:
ImageResizer.Configuration.Config.Current.Plugins
Am now getting the following error when imageJob.Build(); is called:
Could not load file or assembly 'AForge.Imaging, Version=2.2.5.0, Culture=neutral, PublicKeyToken=ba8ddea9676ca48b' or one of its dependencies. The system cannot find the file specified.
Hoping this was another issue with configuration I've added the following using statements to the top of the class that uses ImageResizer:
using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Imaging.ColorReduction;
using AForge.Imaging.ComplexFilters;
using AForge.Imaging.Textures;
The configuration issues are resolved but I am still getting the same error for the AForge libraries. Have opened a new question for this specific issue Here
回答1:
I suspect that the configuration is not being loaded. Can you access the diagnostics page by debugging and inspecting the ImageResizer.Configuration.Config.Current
instance?
You might consider configuring the software by code - creating a new Config instance and installing plugins on it, then using that for each image job.
Overall, I would definitely suggest using it as an HttpModule, the way it was intended - particularly if you want to levergage disk caching.
来源:https://stackoverflow.com/questions/29551938/imageresizing-net-behind-wcf