Posted 3 November 2022, 1:02 am EST
I’m working on .Net MAUI and I used native rendering in my application. So for Windows (WinUi-3), I have drawings rendered on the CanvasRenderTarget object and now I have to provide this as ImageSource(MAUI) to the user.
I tried to get Pixels from canvasrendertarget object and later to the stream source. But setting this stream source to the Image control, I’m not able to get the image output.
renderTarget = new CanvasRenderTarget(CanvasDevice.GetSharedDevice(),(float) 400, (float)400, 96); using (var ds = renderTarget.CreateDrawingSession()) { ds.FillCircle(10, 10, 400, Windows.UI.Color.FromArgb(250, 140, 120, 150)); } byte[] bytes = renderTarget.GetPixelBytes(); //Setting the Stream source to my Image control imageview.Source = ImageSource.FromStream(() => new MemoryStream(bytes));
Not sure what I’m missing, how can I convert WinUi RenderTarget object to MAUI.ImageSource ?