简体   繁体   English

有没有一种线程安全的方法来在ASP.NET Web应用程序上以C#合并图像

[英]Is there a thread safe way to combine images in C# on an asp.net web app

I'm looking to write some code that combines three images in a layered order so that transparency at each layer is preserved. 我正在寻找编写一些代码,这些代码以分层的顺序合并三个图像,以便保留每一层的透明度。 After combining them in memory i want to save the resulting image into a new file. 将它们合并到内存后,我想将生成的图像保存到一个新文件中。 I heard that .net's system.drawing.2D is not a thread safe way of doing this and would be bad in a server app. 我听说.net的system.drawing.2D不是执行此操作的线程安全方法,并且在服务器应用程序中会很糟糕。 Is there something in .net that I can use to do this? .net中有什么我可以用来做的吗?

You're right to note that System.Drawing and all/most? 您正确地注意到System.Drawing和全部/大部分? underlying namespaces are unsafe to use in ASP.NET environments. 基础名称空间在ASP.NET环境中使用是不安全的。 This, at least, is what microsoft claims on the associated MSDN documentation page: http://msdn.microsoft.com/en-us/library/xs6ftd89.aspx and in particular: 至少,这是Microsoft在相关的MSDN文档页面上声明的内容: http : //msdn.microsoft.com/zh-cn/library/xs6ftd89.aspx ,尤其是:

Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Windows或ASP.NET服务中不支持使用System.Drawing命名空间中的类。 Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions. 尝试从这些应用程序类型之一中使用这些类可能会产生意外问题,例如服务性能下降和运行时异常。 For a supported alternative, see Windows Imaging Components. 有关支持的替代方法,请参见Windows Imaging Components。

No further details are given in regards to what's the cause of the problem however this might give you some more insights. 关于导致问题的原因,没有进一步的详细信息, 但这可能会给您带来更多的见解。

All in all, the recommended alternative, windows imaging components, is under-documented however there should be enough on google to get you started (start by reading the article linked above, and checkout the referenced articles in the footer). 总而言之,推荐的替代品Windows成像组件的文档不足,但是google上应该有足够的知识来帮助您入门(首先阅读上面链接的文章,然后在页脚中检出引用的文章)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM