I have a problem with displaying an image it’s bytes comes to my pc serial port as chunks of data, 32 bytes at a time, how to keep all the incoming bytes in the same memory stream, then how can I display this image in a picture box
Here is a piece of code
if (((int)header[0] == 0x76) && (header[1] == 0x00) && (header[2] == 0x32) && (header[3] == 0x00) && (header[4] == 0x00)) /// the header is true ,read the image bytes
{
for (int i = 0; i < 32; i++)
Jpg[i] = (byte)CamPort.ReadByte();
fs.Write(Jpg, 0, Jpg.Length);
for (int i = 1; i < Jpg.Length; i++)
{
if ((Jpg[i - 1] == 0xFF) && (Jpg[i - 0] == 0xD9))// reaching the last two bytes(FF D9) of Jpg //
{
EndFlag = true;
MessageBox.Show("done");
//OneSnap.Image = Image.FromStream(fs);
fs.Close();
}
}
}
else
{
MessageBox.Show("DONE");
}
I would just use a nested loop and add 32 bytes at a time to a larger array.
Something like that should get all your data into one array, then you can do manipulation with/on that data. From there it should be a relatively straight-forward matter to display the data in whichever fashion you’d like.