From 547519b54907773446f4a8b03686e0e093c69414 Mon Sep 17 00:00:00 2001 From: AvKov <37872714+dupitydumb@users.noreply.github.com> Date: Sun, 31 Dec 2023 02:48:06 +0700 Subject: [PATCH] Add project files. --- WebcamSetting.sln | 25 +++ WebcamSetting/App.config | 6 + WebcamSetting/Form1.Designer.cs | 142 ++++++++++++++++ WebcamSetting/Form1.cs | 152 ++++++++++++++++++ WebcamSetting/Form1.resx | 123 ++++++++++++++ WebcamSetting/Program.cs | 22 +++ WebcamSetting/Properties/AssemblyInfo.cs | 36 +++++ .../Properties/Resources.Designer.cs | 71 ++++++++ WebcamSetting/Properties/Resources.resx | 117 ++++++++++++++ WebcamSetting/Properties/Settings.Designer.cs | 30 ++++ WebcamSetting/Properties/Settings.settings | 7 + WebcamSetting/WebcamSetting.csproj | 96 +++++++++++ WebcamSetting/packages.config | 6 + 13 files changed, 833 insertions(+) create mode 100644 WebcamSetting.sln create mode 100644 WebcamSetting/App.config create mode 100644 WebcamSetting/Form1.Designer.cs create mode 100644 WebcamSetting/Form1.cs create mode 100644 WebcamSetting/Form1.resx create mode 100644 WebcamSetting/Program.cs create mode 100644 WebcamSetting/Properties/AssemblyInfo.cs create mode 100644 WebcamSetting/Properties/Resources.Designer.cs create mode 100644 WebcamSetting/Properties/Resources.resx create mode 100644 WebcamSetting/Properties/Settings.Designer.cs create mode 100644 WebcamSetting/Properties/Settings.settings create mode 100644 WebcamSetting/WebcamSetting.csproj create mode 100644 WebcamSetting/packages.config diff --git a/WebcamSetting.sln b/WebcamSetting.sln new file mode 100644 index 0000000..db68d36 --- /dev/null +++ b/WebcamSetting.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33502.453 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebcamSetting", "WebcamSetting\WebcamSetting.csproj", "{22CE3334-7343-4D6E-985A-045E530E18B5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {22CE3334-7343-4D6E-985A-045E530E18B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {22CE3334-7343-4D6E-985A-045E530E18B5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {22CE3334-7343-4D6E-985A-045E530E18B5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {22CE3334-7343-4D6E-985A-045E530E18B5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9B533FF0-55F0-4604-89AD-3C538309F038} + EndGlobalSection +EndGlobal diff --git a/WebcamSetting/App.config b/WebcamSetting/App.config new file mode 100644 index 0000000..787dcbe --- /dev/null +++ b/WebcamSetting/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/WebcamSetting/Form1.Designer.cs b/WebcamSetting/Form1.Designer.cs new file mode 100644 index 0000000..5fd7617 --- /dev/null +++ b/WebcamSetting/Form1.Designer.cs @@ -0,0 +1,142 @@ +namespace WebcamSetting +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.panel2 = new System.Windows.Forms.Panel(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel3 = new System.Windows.Forms.Panel(); + this.comboBox2 = new System.Windows.Forms.ComboBox(); + this.button1 = new System.Windows.Forms.Button(); + this.panel1.SuspendLayout(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.Transparent; + this.panel1.Controls.Add(this.comboBox1); + this.panel1.Location = new System.Drawing.Point(12, 12); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(200, 22); + this.panel1.TabIndex = 0; + // + // panel2 + // + this.panel2.BackColor = System.Drawing.SystemColors.MenuBar; + this.panel2.Controls.Add(this.button1); + this.panel2.Controls.Add(this.comboBox2); + this.panel2.Controls.Add(this.pictureBox1); + this.panel2.Location = new System.Drawing.Point(241, 12); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(547, 426); + this.panel2.TabIndex = 1; + // + // comboBox1 + // + this.comboBox1.BackColor = System.Drawing.SystemColors.ScrollBar; + this.comboBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(0, 0); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(200, 21); + this.comboBox1.TabIndex = 0; + // + // pictureBox1 + // + this.pictureBox1.Location = new System.Drawing.Point(3, 3); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(541, 375); + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // panel3 + // + this.panel3.BackColor = System.Drawing.Color.White; + this.panel3.Location = new System.Drawing.Point(9, 9); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(779, 440); + this.panel3.TabIndex = 1; + // + // comboBox2 + // + this.comboBox2.BackColor = System.Drawing.SystemColors.ScrollBar; + this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.comboBox2.FormattingEnabled = true; + this.comboBox2.Location = new System.Drawing.Point(3, 386); + this.comboBox2.Name = "comboBox2"; + this.comboBox2.Size = new System.Drawing.Size(200, 21); + this.comboBox2.TabIndex = 1; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(209, 386); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(95, 23); + this.button1.TabIndex = 2; + this.button1.Text = "Setting"; + this.button1.UseVisualStyleBackColor = true; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 461); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.Controls.Add(this.panel3); + this.MaximumSize = new System.Drawing.Size(816, 500); + this.MinimumSize = new System.Drawing.Size(816, 500); + this.Name = "Form1"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Webcam Setting"; + this.panel1.ResumeLayout(false); + this.panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.ComboBox comboBox2; + private System.Windows.Forms.Button button1; + } +} + diff --git a/WebcamSetting/Form1.cs b/WebcamSetting/Form1.cs new file mode 100644 index 0000000..aec2eaa --- /dev/null +++ b/WebcamSetting/Form1.cs @@ -0,0 +1,152 @@ +using AForge.Video; +using AForge.Video.DirectShow; +using System; +using System.Drawing; +using System.Windows.Forms; + +namespace WebcamSetting +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + panel1.BackColor = Color.FromArgb(0, Color.Black); + comboBox1.SelectionChangeCommitted += new EventHandler(comboBox1_SelectionChangeCommitted); + comboBox2.SelectionChangeCommitted += new EventHandler(comboBox2_SelectionChangeCommitted); + button1.Click += new EventHandler(button1_Click); + + + GetCamera(); + + } + + public event EventHandler SelectionChangeCommitted; + FilterInfoCollection filterInfoCollection; + VideoCaptureDevice videoCaptureDevice; + + string videoSourceName; + + private void GetCamera() + { + comboBox1.Items.Add("Select Camera"); + filterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice); + foreach (FilterInfo filterInfo in filterInfoCollection) + { + comboBox1.Items.Add(filterInfo.Name); + } + comboBox1.SelectedIndex = 0; + videoSourceName = comboBox1.SelectedItem.ToString(); + + } + + private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e) + { + + videoCaptureDevice = new VideoCaptureDevice(filterInfoCollection[comboBox1.SelectedIndex - 1].MonikerString); + videoSourceName = comboBox1.SelectedItem.ToString(); + videoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame; + videoCaptureDevice.Start(); + + foreach (var resolution in videoCaptureDevice.VideoCapabilities) + { + comboBox2.Items.Add(resolution.FrameSize.Width + "x" + resolution.FrameSize.Height); + } + + + + + } + + private void comboBox2_SelectionChangeCommitted(object sender, EventArgs e) + { + videoCaptureDevice.Stop(); + videoCaptureDevice.VideoResolution = videoCaptureDevice.VideoCapabilities[comboBox2.SelectedIndex]; + videoCaptureDevice.Start(); + } + + private void VideoCaptureDevice_NewFrame(object sender, NewFrameEventArgs eventArgs) + { + pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone(); + } + + //On form close + + //Run Bat file to setting webcam + private void button1_Click(object sender, EventArgs e) + { + Setting(); + } + + + private void Setting() + { + try + { + if (videoCaptureDevice.IsRunning != null && videoCaptureDevice.IsRunning) + { + //check if setting.bat is exist at Documents/WebcamSetting/setting.bat + if (System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WebcamSetting\\setting.bat")) + { + + ExcecuteBat(); + } + else + { + //Show yes no dialog + MessageBox.Show("setting.bat not found, do you want to create it?", "Warning", MessageBoxButtons.YesNo); + //if not exist, create it + Writebat(); + //Run bat file + + } + } + else + { + MessageBox.Show("Please select camera", "Warning", MessageBoxButtons.OK); + } + } + catch (Exception ex) + { + MessageBox.Show("Please Select Camera", "Error", MessageBoxButtons.OK); + } + + + } + + + private void Writebat() + { + //Create new path file at Documents/WebcamSetting/setting.bat + string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WebcamSetting\\setting.bat"; + + //Create new folder at Documents/WebcamSetting + System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WebcamSetting"); + + //Copy ffmpeg.exe to Documents/WebcamSetting/ffmpeg.exe + System.IO.File.Copy(AppDomain.CurrentDomain.BaseDirectory + "ffmpeg.exe", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WebcamSetting\\ffmpeg.exe", true); + //Write bat file + string[] lines = { "chcp 65001 > nul", "ffmpeg -f dshow -show_video_device_dialog true -i video=" + '"' + videoSourceName + '"' }; + System.IO.File.WriteAllLines(path, lines); + MessageBox.Show("Exported to " + path); + + } + + private void ExcecuteBat() + { + try + { + //get root path + string path = AppDomain.CurrentDomain.BaseDirectory + "setting.bat"; + //Open bat file + System.Diagnostics.Process.Start(path); + } + catch (Exception ex) + { + MessageBox.Show("File not found", "Error", MessageBoxButtons.OK); + } + + + } + } +} \ No newline at end of file diff --git a/WebcamSetting/Form1.resx b/WebcamSetting/Form1.resx new file mode 100644 index 0000000..61bc649 --- /dev/null +++ b/WebcamSetting/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + \ No newline at end of file diff --git a/WebcamSetting/Program.cs b/WebcamSetting/Program.cs new file mode 100644 index 0000000..fe0d72d --- /dev/null +++ b/WebcamSetting/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebcamSetting +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/WebcamSetting/Properties/AssemblyInfo.cs b/WebcamSetting/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..35b4a54 --- /dev/null +++ b/WebcamSetting/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WebcamSetting")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WebcamSetting")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("22ce3334-7343-4d6e-985a-045e530e18b5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/WebcamSetting/Properties/Resources.Designer.cs b/WebcamSetting/Properties/Resources.Designer.cs new file mode 100644 index 0000000..e1b788c --- /dev/null +++ b/WebcamSetting/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WebcamSetting.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WebcamSetting.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/WebcamSetting/Properties/Resources.resx b/WebcamSetting/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/WebcamSetting/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WebcamSetting/Properties/Settings.Designer.cs b/WebcamSetting/Properties/Settings.Designer.cs new file mode 100644 index 0000000..498001a --- /dev/null +++ b/WebcamSetting/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WebcamSetting.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/WebcamSetting/Properties/Settings.settings b/WebcamSetting/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/WebcamSetting/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/WebcamSetting/WebcamSetting.csproj b/WebcamSetting/WebcamSetting.csproj new file mode 100644 index 0000000..3df10d4 --- /dev/null +++ b/WebcamSetting/WebcamSetting.csproj @@ -0,0 +1,96 @@ + + + + + Debug + AnyCPU + {22CE3334-7343-4D6E-985A-045E530E18B5} + WinExe + WebcamSetting + WebcamSetting + v4.7.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\AForge.2.2.5\lib\AForge.dll + + + ..\packages\AForge.Video.2.2.5\lib\AForge.Video.dll + + + ..\packages\AForge.Video.DirectShow.2.2.5\lib\AForge.Video.DirectShow.dll + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + \ No newline at end of file diff --git a/WebcamSetting/packages.config b/WebcamSetting/packages.config new file mode 100644 index 0000000..a3c6cdb --- /dev/null +++ b/WebcamSetting/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file