From 3148da02dd3c5ecd7fc2d41c6c190c33d0334d79 Mon Sep 17 00:00:00 2001 From: zqm Date: Fri, 27 Mar 2026 09:27:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8A=E6=94=BE=E5=8A=A8=E6=80=81=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Camera/Camera/Camera.cs | 50 ++++++++++++++++++- .../Framework4.0/Camera/Camera/Camera.csproj | 10 ++-- .../Camera/Test/Form2.Designer.cs | 7 +-- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/Windows/CS/Framework4.0/Camera/Camera/Camera.cs b/Windows/CS/Framework4.0/Camera/Camera/Camera.cs index 726212d..d31c203 100644 --- a/Windows/CS/Framework4.0/Camera/Camera/Camera.cs +++ b/Windows/CS/Framework4.0/Camera/Camera/Camera.cs @@ -23,7 +23,7 @@ namespace Camera private const string PASSWD = "Yexian.net.168"; // 调试模式 - private const Boolean IsDebug = true; + private const Boolean IsDebug = false; // 配置文件目录 private string _configPath; @@ -87,11 +87,18 @@ namespace Camera private static bool _isEmguCvAvailable = false; private static string _emguCvError = ""; + private static bool _isDllExtracted = false; public static bool CheckEmguCv() { try { + if (!_isDllExtracted) + { + ExtractDlls(); + _isDllExtracted = true; + } + using (var testImage = new Image(1, 1)) { testImage.Dispose(); @@ -107,6 +114,47 @@ namespace Camera } } + private static void ExtractDlls() + { + string appDir = AppDomain.CurrentDomain.BaseDirectory; + bool is64Bit = Environment.Is64BitProcess; + + string[] dllFiles = is64Bit + ? new string[] { "x64.cvextern.dll", "x64.opencv_ffmpeg310_64.dll" } + : new string[] { "x86.cvextern.dll", "x86.opencv_ffmpeg310.dll" }; + + string[] destFiles = is64Bit + ? new string[] { "cvextern.dll", "opencv_ffmpeg310_64.dll" } + : new string[] { "cvextern.dll", "opencv_ffmpeg310.dll" }; + + for (int i = 0; i < dllFiles.Length; i++) + { + string destPath = Path.Combine(appDir, destFiles[i]); + if (!File.Exists(destPath)) + { + try + { + using (var stream = typeof(Camera).Assembly.GetManifestResourceStream("Camera." + dllFiles[i])) + { + if (stream != null) + { + using (var fs = new FileStream(destPath, FileMode.Create)) + { + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0) + { + fs.Write(buffer, 0, bytesRead); + } + } + } + } + } + catch { } + } + } + } + public static bool IsEmguCvAvailable() { return _isEmguCvAvailable; diff --git a/Windows/CS/Framework4.0/Camera/Camera/Camera.csproj b/Windows/CS/Framework4.0/Camera/Camera/Camera.csproj index c70e147..dde8635 100644 --- a/Windows/CS/Framework4.0/Camera/Camera/Camera.csproj +++ b/Windows/CS/Framework4.0/Camera/Camera/Camera.csproj @@ -1,4 +1,4 @@ - + @@ -101,10 +101,10 @@ - - - - + + + + diff --git a/Windows/CS/Framework4.0/Camera/Test/Form2.Designer.cs b/Windows/CS/Framework4.0/Camera/Test/Form2.Designer.cs index 6e94bb3..033b6d5 100644 --- a/Windows/CS/Framework4.0/Camera/Test/Form2.Designer.cs +++ b/Windows/CS/Framework4.0/Camera/Test/Form2.Designer.cs @@ -35,16 +35,17 @@ // // pictureBox1 // - this.pictureBox1.Location = new System.Drawing.Point(30, 50); + this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox1.Location = new System.Drawing.Point(0, 0); this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(454, 376); + this.pictureBox1.Size = new System.Drawing.Size(800, 450); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; // // button1 // - this.button1.Location = new System.Drawing.Point(569, 152); + this.button1.Location = new System.Drawing.Point(644, 80); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(109, 49); this.button1.TabIndex = 1;