Hopefully this’ll be a fairly simple answer, but it’s not the easiest thing to google for.
I’m planning to do a lot of painting using simple shapes, but the actual result doesn’t need to be displayed to the user until the final stage, so for the sake of speed, I was wondering if there were existing methods in c#/WPF to draw simple shapes to a buffer without the overhead of a BitmapSource, so at the end I can just copy it into a WritableBitmap.
Something like
PixelFormat pixelFormat = PixelFormats.Default;
int stride = bitmapWidth * pixelFormat.BitsPerPixel / 8;
byte[] pixels new byte[bitmapHeight * stride];
*some static library*.DrawOval(xpos=10,ypos=10,radius=5, pixels, stride, pixelFormat);
Thanks
“Drawing shapes to a buffer” in WPF could be done by drawing shapes into a DrawingVisual using a DrawingContext. When drawing is finished, the DrawingVisual can be rendered into a RenderTargetBitmap.
Example: