Commit 3ea03e07 by 陶然

优化

parent d8359e4a
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
partial class VideoSourcePlayer partial class VideoSourcePlayer
{ {
/// <summary> /// <summary>
/// 必需的设计器变量。 /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// 清理所有正在使用的资源。 /// Clean up any resources being used.
/// </summary> /// </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) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
base.Dispose(disposing); 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> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
this.Paint += new System.Windows.Forms.PaintEventHandler(this.VideoSourcePlayer_Paint); this.Paint += new System.Windows.Forms.PaintEventHandler(this.VideoSourcePlayer_Paint);
this.ParentChanged += new System.EventHandler(this.VideoSourcePlayer_ParentChanged); this.ParentChanged += new System.EventHandler(this.VideoSourcePlayer_ParentChanged);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
#endregion #endregion
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Drawing;
using System.Data;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms;
namespace Kivii.Sample.ImageUploader.Controls namespace Kivii.Sample.ImageUploader.Controls
{ {
using Imaging.Filters; using Imaging.Filters;
using Kivii.Imaging; using Kivii.Imaging;
using Math.Geometry; using Math.Geometry;
using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Windows.Forms;
using Video; using Video;
using Point = System.Drawing.Point; using Point = System.Drawing.Point;
......
...@@ -185,8 +185,9 @@ namespace Kivii.Sample.ImageUploader ...@@ -185,8 +185,9 @@ namespace Kivii.Sample.ImageUploader
{ {
// add all devices to combo // add all devices to combo
cameraQuantity = videoDevices.Count; cameraQuantity = videoDevices.Count;
videoDevice = new VideoCaptureDevice(videoDevices[currentCameraIndex].MonikerString);
gbCamView.Text = videoDevices[currentCameraIndex].Name; gbCamView.Text = videoDevices[currentCameraIndex].Name;
videoDevice = new VideoCaptureDevice(videoDevices[currentCameraIndex].MonikerString);
enumeratedSupportedFrameSizes(videoDevice); enumeratedSupportedFrameSizes(videoDevice);
} }
else else
...@@ -231,17 +232,21 @@ namespace Kivii.Sample.ImageUploader ...@@ -231,17 +232,21 @@ namespace Kivii.Sample.ImageUploader
cbxResolution.Items.Clear(); cbxResolution.Items.Clear();
try 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}", //if (capabilty.FrameSize.Width > 1024) continue;
capability.FrameSize.Width, capability.FrameSize.Height)); tmpVideoCapalilities.Add(capabilty);
cbxResolution.Items.Add(string.Format("{0} x {1}", capabilty.FrameSize.Width, capabilty.FrameSize.Height));
} }
// 获取摄像头支持的分辨率列表
videoCapabilities = tmpVideoCapalilities.ToArray();
// 如果没有支持的分辨率,则添加 "Not supported" // 如果没有支持的分辨率,则添加 "Not supported"
if (cbxResolution.Items.Count == 0) if (videoCapabilities.Length == 0)
{ {
cbxResolution.Items.Add("Not supported"); cbxResolution.Items.Add("Not supported");
} }
...@@ -263,13 +268,13 @@ namespace Kivii.Sample.ImageUploader ...@@ -263,13 +268,13 @@ namespace Kivii.Sample.ImageUploader
else else
{ {
if (videoDevice == null) return; if (videoDevice == null) return;
tbxReportId.Focus();
if ((videoCapabilities != null) && (videoCapabilities.Length != 0)) if ((videoCapabilities != null) && (videoCapabilities.Length != 0))
{ {
videoDevice.VideoResolution = videoCapabilities[selectedIndex]; videoDevice.VideoResolution = videoCapabilities[selectedIndex];
} }
vspCamView.VideoSource = videoDevice; vspCamView.VideoSource = videoDevice;
vspCamView.Start(); vspCamView.Start();
tbxReportId.Focus();
} }
} }
...@@ -485,12 +490,12 @@ namespace Kivii.Sample.ImageUploader ...@@ -485,12 +490,12 @@ namespace Kivii.Sample.ImageUploader
{ {
initFormCtlEnable(false); initFormCtlEnable(false);
setDefault(tbxServiceUrl, tbxUserName, tbxPassword); setDefault(tbxServiceUrl, tbxUserName, tbxPassword);
Thread.Sleep(100);
if (videoDevice == null) initCameras(); if (videoDevice == null) initCameras();
if (videoDevice == null) if (videoDevice == null)
{ {
return; return;
} }
Thread.Sleep(100);
// 默认选择第一个分辨率 // 默认选择第一个分辨率
cbxResolution.SelectedIndex = 0; cbxResolution.SelectedIndex = 0;
}, true); }, true);
...@@ -533,6 +538,7 @@ namespace Kivii.Sample.ImageUploader ...@@ -533,6 +538,7 @@ namespace Kivii.Sample.ImageUploader
private void cbxResolution_SelectedIndexChanged(object sender, EventArgs e) private void cbxResolution_SelectedIndexChanged(object sender, EventArgs e)
{ {
disconnect(); disconnect();
Thread.Sleep(100);
if (cbxResolution.SelectedIndex >= 0) connect(cbxResolution.SelectedIndex); 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