Commit 3ea03e07 by 陶然

优化

parent d8359e4a
......@@ -2,15 +2,15 @@
{
partial class VideoSourcePlayer
{
/// <summary>
/// 必需的设计器变量。
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
......@@ -20,11 +20,11 @@
base.Dispose(disposing);
}
#region 组件设计器生成的代码
#region Component Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
......@@ -35,6 +35,7 @@
this.Paint += new System.Windows.Forms.PaintEventHandler(this.VideoSourcePlayer_Paint);
this.ParentChanged += new System.EventHandler(this.VideoSourcePlayer_ParentChanged);
this.ResumeLayout(false);
}
#endregion
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Kivii.Sample.ImageUploader.Controls
{
using Imaging.Filters;
using Kivii.Imaging;
using Math.Geometry;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using Video;
using Point = System.Drawing.Point;
......
......@@ -185,8 +185,9 @@ namespace Kivii.Sample.ImageUploader
{
// add all devices to combo
cameraQuantity = videoDevices.Count;
videoDevice = new VideoCaptureDevice(videoDevices[currentCameraIndex].MonikerString);
gbCamView.Text = videoDevices[currentCameraIndex].Name;
videoDevice = new VideoCaptureDevice(videoDevices[currentCameraIndex].MonikerString);
enumeratedSupportedFrameSizes(videoDevice);
}
else
......@@ -231,17 +232,21 @@ namespace Kivii.Sample.ImageUploader
cbxResolution.Items.Clear();
try
{
// 获取摄像头支持的分辨率列表
videoCapabilities = videoDevice.VideoCapabilities;
//videoCapabilities = videoDevice.VideoCapabilities;
List<VideoCapabilities> tmpVideoCapalilities = new List<VideoCapabilities>();
// 遍历分辨率列表,并添加到下拉框中
foreach (VideoCapabilities capability in videoCapabilities)
foreach (VideoCapabilities capabilty in videoDevice.VideoCapabilities)
{
cbxResolution.Items.Add(string.Format("{0} x {1}",
capability.FrameSize.Width, capability.FrameSize.Height));
//if (capabilty.FrameSize.Width > 1024) continue;
tmpVideoCapalilities.Add(capabilty);
cbxResolution.Items.Add(string.Format("{0} x {1}", capabilty.FrameSize.Width, capabilty.FrameSize.Height));
}
// 获取摄像头支持的分辨率列表
videoCapabilities = tmpVideoCapalilities.ToArray();
// 如果没有支持的分辨率,则添加 "Not supported"
if (cbxResolution.Items.Count == 0)
if (videoCapabilities.Length == 0)
{
cbxResolution.Items.Add("Not supported");
}
......@@ -263,13 +268,13 @@ namespace Kivii.Sample.ImageUploader
else
{
if (videoDevice == null) return;
tbxReportId.Focus();
if ((videoCapabilities != null) && (videoCapabilities.Length != 0))
{
videoDevice.VideoResolution = videoCapabilities[selectedIndex];
}
vspCamView.VideoSource = videoDevice;
vspCamView.Start();
tbxReportId.Focus();
}
}
......@@ -485,12 +490,12 @@ namespace Kivii.Sample.ImageUploader
{
initFormCtlEnable(false);
setDefault(tbxServiceUrl, tbxUserName, tbxPassword);
Thread.Sleep(100);
if (videoDevice == null) initCameras();
if (videoDevice == null)
{
return;
}
Thread.Sleep(100);
// 默认选择第一个分辨率
cbxResolution.SelectedIndex = 0;
}, true);
......@@ -533,6 +538,7 @@ namespace Kivii.Sample.ImageUploader
private void cbxResolution_SelectedIndexChanged(object sender, EventArgs e)
{
disconnect();
Thread.Sleep(100);
if (cbxResolution.SelectedIndex >= 0) connect(cbxResolution.SelectedIndex);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment