Image creating dynamically using writablebitmap perfomance lag and UI freezing when increasing image size in WASM. #15764
Unanswered
tomchoondal
asked this question in
Q&A
Replies: 2 comments 6 replies
-
Thanks for the question. If your app uses the .NET interpreter (the default), it is likely that this piece of code will be slow. Make sure to use AOT to improve your app's performance. |
Beta Was this translation helpful? Give feedback.
4 replies
-
In visual studio 2022 we are selecting WASM project and Building. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are using WriteableBitmap for creating images dynamically. Its working in wasm but as size of the image increasing (in our case height) the performance lags and the UI freezes.
We used the following pattern.
var height = widget.ImageVM.LineItems.Count; //height varies from 0 to any value (for us 200px after this UI freezes)
var width = widget.ImageVM.LineItems[0].DataPointItems.Count; //width is fixed to 256px
var bm = new WriteableBitmap(width, height);
byte[] imageArray = new byte[height * width * 4];
for (int x = 0; x < height; x++)
{
for (int y = 0; y < imageArray.Length; y += 4)
{
imageArray[y] = 0;
imageArray[y + 1] = 0;
imageArray[y + 2] = 255;
imageArray[y + 3] = 255;
}
}
using (Stream stream = bm.PixelBuffer.AsStream())
{
//write to bitmap
await stream.WriteAsync(imageArray, 0, imageArray.Length);
}
_image.Source = bm;
_image.Height = height;
any suggestions/alternatives for better image creation.
Beta Was this translation helpful? Give feedback.
All reactions