简体   繁体   中英

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. Is there something in .net that I can use to do this?

You're right to note that System.Drawing and all/most? underlying namespaces are unsafe to use in ASP.NET environments. 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:

Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. 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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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