コード例 #1
0
ファイル: Form1.cs プロジェクト: ben12345/Autocaster
        public void ReceiveCallback(IAsyncResult ar)
        {
            UdpClient u = (UdpClient)((UdpState)(ar.AsyncState)).u;
            IPEndPoint e = (IPEndPoint)((UdpState)(ar.AsyncState)).e;
            if (open)
            {
                bytes = u.EndReceive(ar, ref e);

                if (bytes.Length != 4)
                {

                    for (int i = 0; i < bytes.Length; i += 4)
                    {
                        imageData[x + (y * frameWidth)] = (uint)(((uint)bytes[i + 2] << 16) | ((uint)bytes[i + 1] << 8) | bytes[i]);
                        x++;
                    }

                    if (x == frameWidth)
                    {
                        x = 0;
                        y++;
                    }

                    if (y == frameHeight && z < frameCount)
                    {
                        updateImage();
                        currentFrame = z;
                        z++;
                        y = 0;
                    }

                }
                else
                {
                    int g = (bytes[0] >> 0) & 0x01;
                    int r = (bytes[0] >> 1) & 0x01;
                    int y = (bytes[0] >> 2) & 0x01;
                    int b = (bytes[0] >> 3) & 0x01;
                    int o = (bytes[0] >> 4) & 0x01;
                    int s = (bytes[0] >> 5) & 0x01;
                    statuses[z] = String.Format("{0} {1} {2} {3} {4}   {5}", g, r, y, b, o, s);
                }

            }

            if (open)
            {
                UdpState s = new UdpState();
                s.e = e;
                s.u = u;
                u.BeginReceive(new AsyncCallback(ReceiveCallback), s);
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: ben12345/Autocaster
        private void button2_Click(object sender, EventArgs e)
        {
            if (!open)
            {
                frameWidth = int.Parse(widthTextBox.Text);
                frameHeight = int.Parse(heightTextBox.Text);
                frameCount = int.Parse(framesTextBox.Text);

                pictureBox1.Width = frameWidth;
                pictureBox1.Height = frameHeight;

                currentFrame = 0;
                frameTrackBar.Value = 0;
                frameTrackBar.Maximum = frameCount - 1;
                frameLabel.Text = (currentFrame + 1) + " / " + frameCount;

                button2.Text = "Stop Listening";
                udpClient = new UdpClient(0xF00D);
                udpClient.Client.ReceiveBufferSize = frameWidth * frameHeight * frameCount * 4;

                open = true;

                b = new Bitmap[frameCount];

                for (int a = 0; a < frameCount; a++)
                {
                    b[a] = new Bitmap(frameWidth, frameHeight, PixelFormat.Format32bppRgb);
                }

                imageData = new uint[frameWidth * frameHeight];

                statuses = new string[frameCount];

                UdpState s = new UdpState();
                s.e = RemoteIpEndPoint;
                s.u = udpClient;
                udpClient.BeginReceive(new AsyncCallback(ReceiveCallback), s);

                x = 0;
                y = 0;
                z = 0;
                i = 0;
                timer1.Start();
            }
            else
            {
                open = false;
                button2.Text = "Start Listening";
                udpClient.Close();
                timer1.Stop();
            }
        }