带。NET 7系统。常见的绘图在非windows平台中不再可用。我喜欢将我的应用程序迁移到Microsoft。毛伊岛。图形(正如微软在其.NET 6/7的突破性更改页面上所建议的那样(。它们在windows上支持GDI+,这很好,因为它最大限度地减少了迁移的副作用。在Linux或MacOS上,我可以使用SkiaImage实现。
然而,目前尚不清楚如何实现这一目标。文件目前非常有限。从源代码中,我发现了IImageLoaderService
和几个实现以及IImage。
根据平台的不同,我会注册正确的IImageLoaderService
,一切都应该正常。
if (RuntimeInformation.IsOsPlatform(OsPlatform.Windows)
{
services.AddSingleton<IImageLoaderService, GDIImageLoaderService>()
}
else
{
services.AddSingleton<IImageLoaderService, SkiaImageLoaderService>()
}
理论上到目前为止。然而,在引用Microsoft.Maui.Graphics
Nuget之后,只有IImageLoaderService
可用。
如何在windows上注册GDIImageLoaderService
(或者如何调用服务以使用gdi+(?
我以为System.Drawing.Common
只是针对非windows平台删除的。另外,Microsoft.Maui.Graphics
还不是实验性的吗?嗯,GitHub仍然这么说(这很有趣(。无论如何,如果你真的想改变这一点,为什么不在Windows上使用SkiaImageLoaderService
呢?
此外,还有一个关于此的公开错误:https://github.com/dotnet/Microsoft.Maui.Graphics/issues/422
还有整个毛伊岛。图形存储库没有GDImageLoaderService。
事实上,GitHub上没有这个类,所以我猜它可能还没有发布。此外,微软文档称使用SkiaSharp
我想你可以试试这个:
#if WINDOWS
services.AddSingleton<IImageLoadingService, Microsoft.Maui.Graphics.Win2D.SkiaImageLoadingService>();
#endif