本文介绍了如何从事件befor执行方法AcceptTcpClientAsync获取位图变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在使用AForge框架,我从网络摄像头获取图像,然后我想将此图像从服务器发送到客户端。但问题在于,在执行方法AcceptTcpClientAsync并且位图变量为null之后,我得到了位图变量,该变量在事件中。如何在执行方法之前获取图像AcceptTcpClientAsync
代码:
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:
private void Form1_Load(object sender, EventArgs e)
{
StartCapture();
Form1 async = new Form1(51510);
async.Start();
Console.ReadLine();
}
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();
}
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++;
}
}
我想在方法CodingImages中使用图像(位图视频)。
希望,有人可以帮助我。
对不起我的英语
I want to use image(bitmap video) in method CodingImages.
Hope, that someone can help me.
Sorry for my English
推荐答案
这篇关于如何从事件befor执行方法AcceptTcpClientAsync获取位图变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!