Microsoft.Maui.Graphics icon indicating copy to clipboard operation
Microsoft.Maui.Graphics copied to clipboard

[Maui][Windows] Unhandled exception when clipping an image

Open davidbritch opened this issue 3 years ago • 1 comments

The following code clips the image as expected on Android:

            IImage image;
            var assembly = GetType().GetTypeInfo().Assembly;
            using (var stream = assembly.GetManifestResourceStream("GraphicsViewDemos.Resources.Images.dotnet_bot.png"))
            {
                image = GraphicsPlatform.CurrentService.LoadImageFromStream(stream);
            }

            if (image != null)
            {
                PathF path = new PathF();
                path.AppendCircle(100, 90, 80);
                canvas.ClipPath(path);  // Must be called before DrawImage
                canvas.DrawImage(image, 10, 10, image.Width, image.Height);
            }

However, running the code on Windows results in an unhandled exception occurring with the following message: After calling CanvasDrawingSession.CreateLayer, you must close the resulting CanvasActiveLayer before ending the CanvasDrawingSession.

davidbritch avatar Dec 17 '21 16:12 davidbritch

Not implemented on Windows: https://github.com/dotnet/Microsoft.Maui.Graphics/blob/main/src/Microsoft.Maui.Graphics.Win2D.WinUI.Desktop/W2DImage.cs#L66 We need to implement it and also review the Images rendering.

jsuarezruiz avatar Jun 21 '22 07:06 jsuarezruiz