You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The public static void DrawLine(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color, Rect? clipRect = null)
method simply calls the public static void DrawLine(BitmapContext context, int pixelWidth, int pixelHeight, int x1, int y1, int x2, int y2, int color, Rect? clipRect = null) method. Which is public, so the user can directyl call it:
But the other Draw/Fill methods are not following the same logic. It would be good to have a DrawXxx(BitmapContext ...) method for all draw/fill methods. And the WriteableBitmap extension method should create the context, and call the new method whihc receives the context.
It would be event more better if this method will be the extension (non-extesion) method of the BitmapContext. So the user could write:
Other improvemetns:
It would be good to allow to pass Spans to the methods instead of arrays:
Instead of this: public static void FillPolygon(this WriteableBitmap bmp, int[] points, Color color)
the following: public static void FillPolygon(this WriteableBitmap bmp, Span<int> points, Color color)
So the users do not have to create the exact size array, the could use a larger buffer and pass the part of it.
More improvements:
Do not allocate new arrays in the draw/fill methods. Use stackalloc instead. (if the array size is smaller than a limit)
The text was updated successfully, but these errors were encountered:
zgabi
changed the title
Avoid allocation of unnecessray object
Avoid allocation of unnecessary objects
Jun 30, 2022
Great feedback. Thank you. At the time the library was created there was no Span and alike. ;-)
We accept pull request, so if you want to propose some of your changes in a PR that would be good.
For example BitmapContext
The
public static void DrawLine(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color, Rect? clipRect = null)
method simply calls the
public static void DrawLine(BitmapContext context, int pixelWidth, int pixelHeight, int x1, int y1, int x2, int y2, int color, Rect? clipRect = null)
method. Which is public, so the user can directyl call it:But the other Draw/Fill methods are not following the same logic. It would be good to have a DrawXxx(BitmapContext ...) method for all draw/fill methods. And the WriteableBitmap extension method should create the context, and call the new method whihc receives the context.
It would be event more better if this method will be the extension (non-extesion) method of the
BitmapContext
. So the user could write:Other improvemetns:
It would be good to allow to pass Spans to the methods instead of arrays:
Instead of this:
public static void FillPolygon(this WriteableBitmap bmp, int[] points, Color color)
the following:
public static void FillPolygon(this WriteableBitmap bmp, Span<int> points, Color color)
So the users do not have to create the exact size array, the could use a larger buffer and pass the part of it.
More improvements:
Do not allocate new arrays in the draw/fill methods. Use stackalloc instead. (if the array size is smaller than a limit)
The text was updated successfully, but these errors were encountered: