EPPlusSoftware / EPPlus

EPPlus-Excel spreadsheets for .NET
https://epplussoftware.com
Other
1.8k stars 274 forks source link

System.Drawing.Common is deprecated on non-Windows platforms #495

Closed safern closed 2 years ago

safern commented 3 years ago

Hello, I work on the .NET Libraries team, and I saw that this library has a lot of usage in the community and depends on System.Drawing.Common for xplat scenarios.

We made the decision to make System.Drawing.Common a windows only library starting .NET6+ due to a lot of reasons after a long discussion. You can see more details here: https://github.com/dotnet/designs/blob/a15a8c7a324c482c5e38b73e46c2afe56f6bd504/accepted/2021/system-drawing-win-only/system-drawing-win-only.md

Also: https://github.com/dotnet/docs/issues/25257

We wanted to reach out so that you could react to this changes when .NET 6 is released. Also if you have any questions/concerns please do let us know at https://github.com/dotnet/runtime

What is the recommended action to still support winforms/wpf scenarios for example?

You can mark the APIs that need to use System.Drawing.Common to support winforms/wpf as windows only using the SupportedOSPlatform("windows") annotation, and then add new APIs that use another library like ImageSharp or `SkiaSharp.

JanKallman commented 3 years ago

Thanks for the info. I will investigate this further. Are there any future plans for adding xplat drawing functionality into the core framework? I mean, imaging and font handling are basic functions that really should be there.

safern commented 3 years ago

Are there any future plans for adding xplat drawing functionality into the core framework? I mean, imaging and font handling are basic functions that really should be there.

That hasn't been decided yet as currently drawing relies heavily for all its operations on GDI+. At the moment we recommend SkiaSharp or ImageSharp which are great xplat open source libraries for those basic functions.

JanKallman commented 3 years ago

Ok thanks. FYI: SkiaSharp is probably our best bet, but it lacks a lot of image codecs used in Office (tif, wmf, emf) and that are supported by System.Drawing.Common with GDI+. Are you planning to implement these codecs in SkiaSharp or in any other way provide support for them in .NET 6 and onwards? They are still used in Excel, especially .emf which Excel produces when an ActiveX control is created.

safern commented 3 years ago

Thanks for the heads up. That would be a good issue to open on SkiaSharp repository directly. I would imagine they would be open to implement the codecs in SkiaSharp.

JanKallman commented 3 years ago

Great, I'll do that. Thanks for your help with this.

emisand commented 2 years ago

@JanKallman I have been migrating our company solution from System.Drawing.Common to ImageSharp. I think it's one of the most straightforward options to choose, it's fully made with .NET code, and it does not have any external dependencies to binaries in the system like SkiaShap or Maui have.

It does suport TIFF, but does not support EMF or the now ancient WMF. Details on the supported formats are here: https://github.com/SixLabors/ImageSharp/tree/main/src/ImageSharp/Formats

You will start by adding these two package references:

<PackageReference Include="SixLabors.ImageSharp" Version="2.0.0" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />

Documentation on the image handling: https://docs.sixlabors.com/articles/imagesharp/gettingstarted.html Documentation on the graphics drawing: https://docs.sixlabors.com/articles/imagesharp.drawing/gettingstarted.html

For a quick release on Linux support for .NET 6 I would recommend to temporarily drop support of EMF and WMF on the linux release binaries until encoders/decoders for those formats are developed on ImageSharp or any other newer Image processing library. There are probably some open source nuget packages for the specific handling of EMF and WMF as they are metafiles based on traditional codecs.

JanKallman commented 2 years ago

@emisand We will release EPPlus 6-beta in the coming days where we replace System.Drawing.Common with native code for all Excel supported image types. See https://github.com/EPPlusSoftware/EPPlus/wiki/Breaking-Changes-in-EPPlus-6 (this is still work in progress). So we will likely not need ImageSharp. We have also implemented interfaces for imaging and text measuring, so using other libraries will be possible if needed. Feel free to test it once we release the beta or try it right now using this branch... https://github.com/EPPlusSoftware/EPPlus/tree/beta/epplus6

emisand commented 2 years ago

Thanks for the update, that's great news!

JanKallman commented 2 years ago

Fixed in 6.0.3. EPPlus will no longer need System.Drawing.Common, as native support for images and autofit columns has been implemented. System.Drawing.Common can still be used via the EPPlus.System.Drawing for supported environments.