how*_*her 5 .net c# system.drawing .net-maui
对于 .NET 7,System.Common.Drawing 不再在非 Windows 平台上使用。我喜欢将我的应用程序迁移到 Microsoft.Maui.Graphics(正如 Microsoft 在 .NET 6/7 的重大更改页面上建议的那样)。\n它们支持 Windows 上的 GDI+,这非常好,因为它可以最大限度地减少迁移的副作用。在 Linux 或 MacOS 上,我可以使用 SkiaImage 实现。
\n然而它\xe2\x80\x99s不清楚如何实现这一点。目前的文档非常有限。从源代码中我找到了IImageLoaderServiceIImage 和几个实现。
根据平台,我会注册权利IImageLoaderService,一切都应该正常。
if (RuntimeInformation.IsOsPlatform(OsPlatform.Windows) \n{ \n services.AddSingleton<IImageLoaderService, GDIImageLoaderService>()\n} \nelse \n{\nservices.AddSingleton<IImageLoaderService, SkiaImageLoaderService>() \n}\nRun Code Online (Sandbox Code Playgroud)\n理论上到目前为止。但是,在引用Microsoft.Maui.GraphicsNuget 后,仅IImageLoaderService可用。
如何GDIImageLoaderService在 Windows 上注册(或如何调用服务以使用 gdi+)?
我以为System.Drawing.Common只有非 Windows 平台才会被删除。还有,不是Microsoft.Maui.Graphics还在实验吗?好吧,GitHub 仍然这么说(这很有趣)。不管怎样,SkiaImageLoaderService如果你真的想改变这一点,为什么不也用于 Windows 呢?
另外,还有一个关于此的开放错误:https ://github.com/dotnet/Microsoft.Maui.Graphics/issues/422
此外,整个 Maui.Graphics 存储库没有GDIImageLoaderService。
事实上,GitHub 上没有这个类,所以我猜它可能还没有发布。微软文档还说使用SkiaSharp
我想你可以试试这个:
#if WINDOWS
services.AddSingleton<IImageLoadingService, Microsoft.Maui.Graphics.Win2D.SkiaImageLoadingService>();
#endif
Run Code Online (Sandbox Code Playgroud)