C# AForge设定可用解析度

程式如下

// 获取所有可用的视讯输入设备
FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

// 如果有可用的视讯设备
if (videoDevices.Count > 0)
{
    // 选择第一个视讯设备(您可以根据需求更改索引)
    VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);

    // 取得视讯设备的所有可用解析度
    VideoCapabilities[] availableResolutions = videoSource.VideoCapabilities;

    // 选择所需的解析度,例如,选择第一个可用的解析度
    if (availableResolutions.Length > 0)
    {
        videoSource.VideoResolution = availableResolutions[0];
    }

    // 将 videoSource 连接到您的 PictureBox 或其他显示控制项
    videoSource.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
    videoSource.Start();
}

void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    // 在此处处理每一个新的影格
    Bitmap videoFrame = (Bitmap)eventArgs.Frame.Clone();
    pictureBox1.Image = videoFrame;

    // 请确保在不再需要时停止 videoSource
}

 

自我LV~