I am trying to write a drawing application that allows users to select two points on canvas and draws a line between those points pixel-by-pixel. In WinForms that would be an easy solution - create a canvas, get its bitmap, draw on the bitmap using the SetPixel
method, and replace the canvas bitmap. I am wondering if there is a way to do this in a similar way in AvaloniaUI? From what I understood, it uses SkiaSharp under the hood. However, solutions to render SKCanvas
on Avalonia.Controls.Canvas
seem... hard. Although SKBitmap
also has the SetPixel
method. The question is not about how to draw a line - it is about how to set single pixels on Bitmap in AvaloniaUI
and set this bitmap to the Avalonia.Controls.Canvas
.
Here are some links I found:
- https://github.com/AvaloniaUI/Avalonia/pull/2371
- https://github.com/AvaloniaUI/Avalonia/issues/2492
- AvaloniaUI - How to draw directly on the canvas - Unfortunately, I am not allowed to draw on the canvas itself.
- Artifacts on Avalonia WriteableBitmap BitmapContext - unsafe code, three extension methods... while an option seems a little bit too complex.
P.S. As tempting as this may sound, drawing a rectangle-by-rectangle of size 1x1 as in the official documentation example (https://docs.avaloniaui.net/docs/controls/canvas) is also not allowed by the university.
P.P.S. I am not asking anyone to do the homework for me - in case you are worried about that please, consider this a framework comparison question, not a "please do that for me" one. I have found and linked solutions that I can use - it just seems to me that there should be a more easy way to achieve the result I seek. That's why I have asked the question - in case I missed something.
Doing a Jedi thing: this is not some student trying to lay off his work on other people. You can go by your business