Click here to Skip to main content
15,888,018 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I'm use AForge framework and i get image capture from webcam, then i want to send this image from server to client. But the problem consists of that i get the bitmap variable, which gets in event, after executing method AcceptTcpClientAsync and bitmap variable is null. How to get image before executing method AcceptTcpClientAsync
Code:
C#
private void Form1_Load(object sender, EventArgs e)
        {
            StartCapture();
            Form1 async = new Form1(51510);
            async.Start();
            Console.ReadLine();
        }

C#
public void StartCapture()
        {
            VidoeCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            FinalVideo = new VideoCaptureDevice(VidoeCaptureDevices[0].MonikerString);
            FinalVideo.VideoResolution = FinalVideo.VideoCapabilities[2];
            FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
            FinalVideo.Start();
            Thread.Sleep(2000);
        }
        void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            video = (Bitmap)eventArgs.Frame.Clone();
        }

C#
public async void Start()
        {
            //Thread.Sleep(10000);
            IPAddress ipAddre = IPAddress.Loopback;
            TcpListener listener = new TcpListener(ipAddre, _listeningPort);
            listener.Start();
            LogMessage("Server is running");
            LogMessage("Listening on port " + _listeningPort);

            while (true)
            {
                //CaptureImageFromCamera captureFromCamera = new CaptureImageFromCamera();
                //Bitmap image = captureFromCamera.StartCapture();
                CodingImage img = new CodingImage();
                buffer = img.CodingImages(video);
                count = buffer.Length;
                lenght = buffer.Length.ToString();
                LogMessage("Waiting for connections...");
                try
                {
                    var tcpClient = await listener.AcceptTcpClientAsync();
                    HandleConnectionAsync(tcpClient);
                }
                catch (Exception exp)
                {
                    LogMessage(exp.ToString());
                }
                i++;
            }

        }


I want to use image(bitmap video) in method CodingImages.
Hope, that someone can help me.
Sorry for my English
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900