1 year ago
#379564
Bharani
Performance improvement on rendering - WinUi 3
I am working on .Net MAUI and new to native rendering. I am trying to render a line with stroke width based on the touch dragged velocity. For this, I have calculated Bezier points with stroke width and stored calculated points and rendered repeatedly for each interaction. This results in performance issues on higher point counts. Since we don't have bitmap support on MAUI yet, I have raised feature request for the same and this was considered MAUI team. To overcome this for now, I have moved to native rendering for android, windows and ios platforms.
For Android, I have drawn the points on bitmap parallelly and rendered the existing bitmap to the view on each interaction. So this lets canvas draw the bitmap alone at invalidate. This saves lots of work on rendering.
Now for WinUI 3, I have tried the following cases but it is not efficient as Android,
We cannot add segments, since the width of the line needs to be increased linearly bases on velocity.
Tried creating a writablebitmap, and modified easy pixel on rendering as below.
image = new Image();
bitmap = new WriteableBitmap((int)Width, (int)Height);
image.Height this.Height;
image.Width = this.Width;
image.Source = bitmap;
stream = fastRenderSurface.PixelBuffer.AsStream();
buffer = new byte[(int)(this.Width) * (int)(this.Height) * 4];
grid.Childern.Add(image);
Used the pixel buffer and manipulated pixels for rendering points but the line is aliased.
I have referred existing SignaturePad samples in windows and xamarin which is achieved using InkPresenter. But we don't have support for InkPresenter control in WinUi-3.
I think the possible solution is to draw points on bitmap using W2DCanvas session available here, but we don't have direct API's here like Android. Can anyone suggest me how to render on bitmap using session or is there any other possible solution to approach this?.
Thanks.
winui-3
maui
.net-maui
0 Answers
Your Answer