【发布时间】:2015-06-15 14:41:32
【问题描述】:
我一直在为我的公司在 Azure 上构建的一些图像处理服务评估 Nathanael Jones 惊人的图像库和插件。在获得许可证之前,我们正在对它们进行全面测试,以确保它们适合我们的场景。帮自己一个忙,看看Here。
在 ASP.NET MVC Web 应用程序中使用这些插件时,我获得了巨大的成功。我在从 UI 发布到的控制器中使用图像服务器功能。裁剪、调整大小和简单/高级过滤器按预期工作。
我遇到的问题是当我将此功能作为该应用程序中的类库移动到 WCF 服务时。裁剪和调整大小完全按照预期工作,但是所有过滤指令(亮度、对比度、棕褐色等)要么被忽略,要么静默失败。这是图像处理代码:
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();
我已将 MVC 应用程序使用的 Web.Config 设置复制到使用 ImageResizing 包(来自 Nuget)的类库的 App.Config。
<configuration>
<configSections>
<section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false" />
</configSections>
<resizer>
<plugins>
<add name="SimpleFilters" />
<add name="AdvancedFilters" />
</plugins>
</resizer>
</configuration>
为了确定,我还包括了主库和插件的 using 语句:
using ImageResizer;
using ImageResizer.Plugins.AdvancedFilters;
using ImageResizer.Plugins.SimpleFilters;
正如我所提到的,当移动到带有 WCF 服务的类库时,裁剪和调整大小可以完美地工作,但是过滤器会默默地失败。图像会按照说明进行裁剪和调整大小,但不会将过滤器应用于图像。我已经尝试了几种安装库的变体(甚至包括我的解决方案中每个项目的包)。
我的 WCF 服务可以作为 NET.TCP 端点托管吗?我是否应该考虑更新我的体系结构以通过 WCF 服务发布到的 Web API 来支持成像服务?
更新
我通过在代码中安装插件来绕过 Web.Config/App.Config,如下所示:
ImageResizer.Configuration.Config.Current.Plugins.Install(new ImageResizer.Plugins.SimpleFilters.SimpleFilters());
ImageResizer.Configuration.Config.Current.Plugins.Install(new ImageResizer.Plugins.AdvancedFilters.AdvancedFilters());
我已验证插件现在已加载到:
ImageResizer.Configuration.Config.Current.Plugins
现在调用 imageJob.Build(); 时出现以下错误:
无法加载文件或程序集“AForge.Imaging, Version=2.2.5.0, Culture=neutral, PublicKeyToken=ba8ddea9676ca48b”或其依赖项之一。系统找不到指定的文件。
希望这是配置的另一个问题,我在使用 ImageResizer 的类的顶部添加了以下 using 语句:
using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Imaging.ColorReduction;
using AForge.Imaging.ComplexFilters;
using AForge.Imaging.Textures;
配置问题已解决,但我仍然收到 AForge 库的相同错误。已针对此特定问题打开一个新问题Here
【问题讨论】:
-
WCF 最佳实践:不要使用 WCF。
-
离题,但你能详细说明一下吗?您的问题是否与性能等重要问题有关,或者您只是不喜欢使用 WCF(是的,它可能很复杂)。在我的场景中,我有 X 个 .Net 客户端(都在 Azure 中),它们需要使用本机 .Net 对象与集中式服务进行安全通信。这一切都是通过同一个 Affinity Group 内的直接 Net.TPC 调用来完成的。但是,如果您有正当的担忧,我非常愿意听取他们的意见。如果您有替代架构,请分享,我很想听听!
-
与论坛网站不同,我们不使用“谢谢”、“感谢任何帮助”或Stack Overflow 上的签名。请参阅“Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?.
-
供应商很少声明“不再投资”任何东西,这与良好的商业惯例背道而驰。将支持 .NET Full/legacy,但只有在不存在兼容性风险时才会修复错误。 Microsoft is switching to OData/Web API internally,所以很清楚他们的投资去向了。
-
另外,phil 攻击了一项技术。 @JohnSaunders 回复了人身攻击,违反了SO Rule #1。人们在互联网上是错误的 - 这很正常 - 不要个人认为。现在得回去工作了。
标签: c# asp.net wcf image-resizing imageresizer