[英].NET Core System.Drawing.Common PrintDocument doesn't work on Linux
[英].NET 6/7 Migration from System.Drawing.Common to Microsoft.Maui.Graphics
在 .NET 7 中,System.Common.Drawing 在非 Windows 平台上不再可用。 我喜歡將我的應用程序遷移到 Microsoft.Maui.Graphics(正如 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
整個 Maui.Graphics 存儲庫也沒有GDIImageLoaderService 。
實際上,GitHub 上沒有任何東西有這個類,所以我猜它可能還沒有出來。 Microsoft 文檔還說要使用SkiaSharp
你可以試試這個,我猜:
#if WINDOWS
services.AddSingleton<IImageLoadingService, Microsoft.Maui.Graphics.Win2D.SkiaImageLoadingService>();
#endif
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.