The component has worked really well for me and has a lot of useful stuff, thanks for publishing it.
I am currently trying to implement a Barcode-Reader into my blazor website. I've already written a class a while back that can read barcodes from images (System.Drawing.Images
or Bitmaps
).
So now I only need a way to retrieve all streamed images so I can check them for barcodes.
I thought this would be quite easy because the VideoMedia
component has an OnData
event, that also gives a byte[]
with it. I tried converting this byte array to a System.Drawing.Image
forever until I finally figured out that the given array isn't actually a valid image.
The given data depends on the set Timeslice
in the component. The higher it is set, the more data will be given, but it also takes longer to raise the event.
So now I'm stuck here with a ton of data that I can't do anything with and ask myself, why does that OnData
event even exist? What's the purpose of it? It seems to me that the only way this could be used is the one implemented in the demo - showing the user how much data is received per second.
Is there no way to get each frame of the stream in any reliable way? Like an OnNewFrew
event, that would fire each time the image of the stream is updated.
I got one solution working, but it is very ugly and the stream will lag very badly when using it.
I set a Timeslice
of 250, so in my understanding, each 250ms the OnData
event is fired. With the following code, I managed to get the images as System.Drawing.image
:
private async void OnData()
{
Image img = null;
// Get the base64 code of the current image
string data = await CameraControl.CaptureImageAsync();
// Remove the first 22 characters ('data:image/png;base64,')
data = data.Remove(0, 22);
// Convert the valid image string to a byte[]
byte[] dataArr = Convert.FromBase64String(data);
// Convert the byte[] to a System.Drawing.Image using a MemoryStream
using (MemoryStream ms = new(dataArr))
{
img = Image.FromStream(ms);
}
// Here I check the img for barcodes with my own class (not relevant for the post)
}