//绘制图片
        private static void DrawPixelImage(object obj)
        {
            try
            {
                DrawImageParam param = (DrawImageParam)obj;
                //int CameraNum = param.CameraNum;
                byte[] imgcp = (byte[])param.imagesource;
                //byte[] imgcp = (byte[])imgsrc;
                SockPack SockPicture = new SockPack();
                SockPicture = (SockPack)BytesToStruct(imgcp, SockPicture.GetType());
                char[] SerialNum = SockPicture.SerialNum;
                int    CameraNum = SerialNum2CameraNum(SerialNum);
                Bitmap bmp       = new Bitmap(picWidth, picHeight);
                for (int i = 0; i < picHeight; i++)
                {
                    for (int j = 0; j < picWidth; j++)
                    {
                        if (SockPicture.Picture[i * picWidth + j] <= 255 && SockPicture.Picture[i * picWidth + j] >= 0)
                        {
                            bmp.SetPixel(j, i, Color.FromArgb(SockPicture.Picture[i * picWidth + j], SockPicture.Picture[i * picWidth + j], SockPicture.Picture[i * picWidth + j]));
                        }
                        else
                        {
                            bmp.SetPixel(j, i, Color.FromArgb(0, 0, 0));
                        }
                        //bmp.SetPixel(j, i, Color.FromArgb(SockPicture.Picture[i*picWidth+j], SockPicture.Picture[i * picWidth + j], SockPicture.Picture[i * picWidth + j]));
                    }
                }
                //byte[] filepath = System.IO.File.ReadAllBytes("f0.jpg");

                //FileStream fs = new FileStream("f0.jpg",FileMode.OpenOrCreate,FileAccess.Write,FileShare.ReadWrite);
                MemoryStream ms = new MemoryStream();
                bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                string base64 = Convert.ToBase64String(ms.ToArray());
                //if (@default.Label4.InvokeRequired)
                //{

                //}


                ImageUrl[CameraNum] = "data:image/png;base64," + base64;
                Frame[CameraNum]    = SockPicture.Framecnt.ToString();

                bmp.Dispose();
                ms.Dispose();
                //SockPicture.Picture
            }
            catch (System.IndexOutOfRangeException)
            {
                return;
            }

            return;
        }
        /// <summary>

        /// 接收消息

        /// </summary>

        /// <param name="clientSocket"></param>

        private static void ReceiveMessage(object obj)

        {
            ReciveMessageParam param = (ReciveMessageParam)obj;

            int CameraNum = param.CameraNum;

            Socket myClientSocket = param.clientSocket;

            int recievenum = 1;

            int packagepick = 0;

            //通过clientSocket接收数据
            List <byte> resultadd = new List <byte>();

            byte[] result = new byte[Packagebag];

            while (true)

            {
                try

                {
                    // while (System.Convert.ToBoolean(myClientSocket.Available))
                    //{
                    // int receiveNumber = myClientSocket.Receive(result);
                    //Console.WriteLine("111")
                    //}
                    //while (recievenum != 0)
                    //{

                    byte[] resultonce = new byte[300000];

                    recievenum = myClientSocket.Receive(resultonce);

                    //判断读出的为新字节
                    if (recievenum != 0)
                    {
                        resultadd.AddRange(resultonce);
                        packagepick = packagepick + recievenum;
                    }


                    //for (int i = packagepick; i < packagepick + recievenum; i++)
                    //{
                    //    resultadd[i] = resultonce[i-packagepick];
                    //}


                    //总字节数超过一包
                    if (packagepick >= Packagebag)
                    {
                        //得出所在包数据
                        result = resultadd.ToArray().Skip(0).Take(Packagebag).ToArray();
                        //其后数据迁移
                        byte[] Exchange = resultadd.ToArray().Skip(Packagebag).Take(packagepick - Packagebag).ToArray();

                        packagepick = packagepick - Packagebag;

                        resultadd.Clear();
                        resultadd.AddRange(Exchange);

                        Thread DrawImageThread = new Thread(DrawPixelImage);

                        DrawImageParam dparam = new DrawImageParam();

                        dparam.CameraNum = CameraNum;

                        dparam.imagesource = (byte[])result.Clone();

                        DrawImageThread.Start(dparam);
                        // SockPack SockPicture = new SockPack();
                        // SockPicture = (SockPack)BytesToStruct(result, SockPicture.GetType());


                        // Console.WriteLine("{0}帧图像,第一个像素值为{1},最后一个像素值为{2}", SockPicture.Framecnt.ToString(), SockPicture.Picture[0].ToString(), SockPicture.Picture[259 * 205 - 1].ToString());
                    }


                    Thread.Sleep(5);

                    //Console.WriteLine("接收客户端{0}消息{1}", myClientSocket.RemoteEndPoint.ToString(), Encoding.UTF8.GetString(result, 0, receiveNumber));



                    //Console.WriteLine("接收客户端{0}消息{1}", myClientSocket.RemoteEndPoint.ToString(), result);
                }

                catch (Exception ex)

                {
                    Console.WriteLine(ex.Message);

                    myClientSocket.Shutdown(SocketShutdown.Both);

                    myClientSocket.Close();

                    break;
                }
            }
        }