Mark Bath
Mark Bath

Reputation: 92

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?

Upvotes: 0

Views: 516

Answers (1)

Polity
Polity

Reputation: 15130

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

Upvotes: 1

Related Questions