Microsoft.Maui.Graphics
Microsoft.Maui.Graphics copied to clipboard
[Maui][Windows] Unhandled exception when clipping an image
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.
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.