1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| int k;
int i = 0, j, pos1 = 0, pos2 = 0;
char indicateur = '0';
ASCIIEncoding asen = new ASCIIEncoding();
String str = "SJ" + '\r';
byte[] ba = asen.GetBytes(str);
byte[] bb = new byte[65536];
Stream stm = tcpclnt.GetStream();
jpeg_grab = 1;
stm.Write(ba, 0, ba.Length);
k = stm.Read(bb, 0, 65535);
byte[] bc = new byte[k];
// detection de la chaine ACK
while (i < k && indicateur == '0')
{
if (bb[i] == 'A')
{
i++;
if (bb[i] == 'C')
{
i++;
if (bb[i] == 'K')
{
i = i + 2; // 2 pour le \r
pos1 = i;
indicateur = '1';
}
}
}
else
i++;
}
// detection de la chaine JPG_END
while (i < k && indicateur == '1')
{
if (bb[i] == 'J')
{
i++;
if (bb[i] == 'P')
{
i++;
if (bb[i] == 'G')
{
pos2 = i - 3;// JPG
indicateur = '2';
for (j = 0; j < pos2 - pos1; j++)
bc[j] = bb[pos1 + j];
System.IO.File.WriteAllBytes("test.jpg", bc);
}
}
}
else
i++;
}
jpeg_grab = 0;
cam_PictureBox1.ImageLocation = "test.jpg"; |
Partager