From e49ab3d3d1307183288d791598532f916d577546 Mon Sep 17 00:00:00 2001 From: David Britch Date: Mon, 19 Jun 2023 13:05:41 +0100 Subject: [PATCH] Load images on Windows (#357) --- .../Drawables/DrawingDrawable.cs | 20 +++++++++++++------ .../Drawables/ImagesDrawable.cs | 1 - 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/7.0/UserInterface/Views/GraphicsViewDemos/GraphicsViewDemos/Drawables/DrawingDrawable.cs b/7.0/UserInterface/Views/GraphicsViewDemos/GraphicsViewDemos/Drawables/DrawingDrawable.cs index 7541e29..b9bc2fb 100644 --- a/7.0/UserInterface/Views/GraphicsViewDemos/GraphicsViewDemos/Drawables/DrawingDrawable.cs +++ b/7.0/UserInterface/Views/GraphicsViewDemos/GraphicsViewDemos/Drawables/DrawingDrawable.cs @@ -3,6 +3,8 @@ using Font = Microsoft.Maui.Graphics.Font; using IImage = Microsoft.Maui.Graphics.IImage; #if IOS || ANDROID || MACCATALYST using Microsoft.Maui.Graphics.Platform; +#elif WINDOWS +using Microsoft.Maui.Graphics.Win2D; #endif namespace GraphicsViewDemos.Drawables @@ -146,20 +148,22 @@ namespace GraphicsViewDemos.Drawables { public void Draw(ICanvas canvas, RectF dirtyRect) { -#if IOS || ANDROID || MACCATALYST IImage image; Assembly assembly = GetType().GetTypeInfo().Assembly; using (Stream stream = assembly.GetManifestResourceStream("GraphicsViewDemos.Resources.Images.dotnet_bot.png")) { +#if IOS || ANDROID || MACCATALYST // PlatformImage isn't currently supported on Windows. image = PlatformImage.FromStream(stream); +#elif WINDOWS + image = new W2DImageLoadingService().FromStream(stream); +#endif } if (image != null) { canvas.DrawImage(image, 10, 10, image.Width, image.Height); } -#endif } } @@ -288,13 +292,16 @@ namespace GraphicsViewDemos.Drawables { public void Draw(ICanvas canvas, RectF dirtyRect) { -#if IOS || ANDROID || MACCATALYST IImage image; var assembly = GetType().GetTypeInfo().Assembly; using (var stream = assembly.GetManifestResourceStream("GraphicsViewDemos.Resources.Images.dotnet_bot.png")) { +#if IOS || ANDROID || MACCATALYST // PlatformImage isn't currently supported on Windows. image = PlatformImage.FromStream(stream); +#elif WINDOWS + image = new W2DImageLoadingService().FromStream(stream); +#endif } if (image != null) @@ -304,7 +311,6 @@ namespace GraphicsViewDemos.Drawables canvas.ClipPath(path); // Must be called before DrawImage canvas.DrawImage(image, 10, 10, image.Width, image.Height); } -#endif } } @@ -312,13 +318,16 @@ namespace GraphicsViewDemos.Drawables { public void Draw(ICanvas canvas, RectF dirtyRect) { -#if IOS || ANDROID || MACCATALYST IImage image; var assembly = GetType().GetTypeInfo().Assembly; using (var stream = assembly.GetManifestResourceStream("GraphicsViewDemos.Resources.Images.dotnet_bot.png")) { +#if IOS || ANDROID || MACCATALYST // PlatformImage isn't currently supported on Windows. image = PlatformImage.FromStream(stream); +#elif WINDOWS + image = new W2DImageLoadingService().FromStream(stream); +#endif } if (image != null) @@ -326,7 +335,6 @@ namespace GraphicsViewDemos.Drawables canvas.SubtractFromClip(60, 60, 90, 90); canvas.DrawImage(image, 10, 10, image.Width, image.Height); } -#endif } } } diff --git a/7.0/UserInterface/Views/GraphicsViewDemos/GraphicsViewDemos/Drawables/ImagesDrawable.cs b/7.0/UserInterface/Views/GraphicsViewDemos/GraphicsViewDemos/Drawables/ImagesDrawable.cs index d6bbc29..1e18ae7 100644 --- a/7.0/UserInterface/Views/GraphicsViewDemos/GraphicsViewDemos/Drawables/ImagesDrawable.cs +++ b/7.0/UserInterface/Views/GraphicsViewDemos/GraphicsViewDemos/Drawables/ImagesDrawable.cs @@ -2,7 +2,6 @@ using Microsoft.Maui.Graphics.Platform; #elif WINDOWS using Microsoft.Maui.Graphics.Win2D; -using System.IO; #endif using System.Reflection; using IImage = Microsoft.Maui.Graphics.IImage;