c# – Working with an image through System.Windows.Media VS System.Drawing

Question:

Tell me, what space is better to use when working with images in new projects?

It seems, if you look superficially, the functionality is similar.

Is there any difference in performance or behind the scenes is it 2 wrappers over the good old GDI+?

So far, I have come across the fact that WPF can display images of the ImageSource type, and the Image from the System.Drawing space needs to be cast additionally.

And here's the question itself, does it make sense to use System.Windows.Media everywhere or it all depends on the final tasks and if it is not known with which GUI the final library will work, then it is better to return Image from Drawing , and the user himself will cast it to the desired type himself ?

It seems like System.Drawing lies as a separate independent library, while System.Windows.Media lies in the WPF framework. It turns out that all the same Drawing needs to be used everywhere?

Enumerations, by the way, are also duplicated between spaces. For example, listing colors.

Answer:

If you don’t know which GUI to work with and talk about new projects, then it makes sense to make a project on .NET Core and rely only on cross-platform libraries. When using a cross-platform approach, System.Drawing proved to be the best. To use it, you need to add the System.Drawing.Common NuGet package.

I tried various alternatives from here , but they were either not cross-platform, contained bugs, or it was not very easy to add a project without a bunch of additional steps.

About returning a concrete type: I don't really agree about using the System.Drawing.Image type for the end user, I'd rather return an array of bytes, or if it's a Rest API, then return a Base64 string. In general, I find it sufficient to return any type that is compatible with the .NET Standard.

Scroll to Top