From d0ded5cd9bf5070a120bad58b5be21fe2ac6a4ff Mon Sep 17 00:00:00 2001
From: C3032 <C3032@BC3032>
Date: 星期六, 20 十二月 2025 16:41:09 +0800
Subject: [PATCH] test

---
 IDViewer_2D/ImageDisplayWindow .xaml.cs |  125 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 125 insertions(+), 0 deletions(-)

diff --git a/IDViewer_2D/ImageDisplayWindow .xaml.cs b/IDViewer_2D/ImageDisplayWindow .xaml.cs
new file mode 100644
index 0000000..d33ec06
--- /dev/null
+++ b/IDViewer_2D/ImageDisplayWindow .xaml.cs
@@ -0,0 +1,125 @@
+锘縰sing OpenCvSharp;
+using OpenCvSharp.WpfExtensions;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace SmartScanner
+{
+    /// <summary>
+    /// ImageDisplayWindow.xaml 鐨勪氦浜掗�昏緫
+    /// </summary>
+    public partial class ImageDisplayWindow : System.Windows.Window
+    {
+        private List<string> _imagePaths = new List<string>();
+        private int _currentIndex = -1;
+        public ImageDisplayWindow()
+        {
+            InitializeComponent();
+        }
+        public void AddImage(List<string> imagePath)
+        {
+            for (int i = 0; i < imagePath.Count; i++)
+            {
+                if (!File.Exists(imagePath[i]))
+                {
+                    MessageBox.Show($"鍥剧墖涓嶅瓨鍦�: {imagePath}", "閿欒", MessageBoxButton.OK, MessageBoxImage.Error);
+                    return;
+                }
+            }
+            // 娣诲姞鍒板垪琛�
+            //_imagePaths = imagePath;
+            _imagePaths = new List<string>(imagePath);
+            ShowImage(0);
+        }
+
+        private void ShowImage(int index)
+        {
+            if (index < 0 || index >= _imagePaths.Count) return;
+
+            _currentIndex = index;
+            string imagePath = _imagePaths[index];
+
+            try
+            {
+                // 浣跨敤OpenCvSharp璇诲彇鍥剧墖
+                using (Mat image = Cv2.ImRead(imagePath, ImreadModes.Color))
+                {
+                    if (image.Empty())
+                    {
+                        throw new Exception("鍥剧墖鍔犺浇澶辫触");
+                    }
+
+                    // 浣跨敤Dispatcher纭繚UI绾跨▼鏇存柊
+                    Dispatcher.Invoke(() =>
+                    {
+                        ResultImage.Source = image.ToBitmapSource();
+                        Title = $"鍥剧墖鏌ョ湅 ({index + 1}/{_imagePaths.Count}) - {System.IO.Path.GetFileName(imagePath)}";
+
+                        // 鏇存柊鎸夐挳鐘舵��
+                        PrevButton.IsEnabled = index > 0;
+                        NextButton.IsEnabled = index < _imagePaths.Count - 1;
+                    });
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show($"鍔犺浇鍥剧墖澶辫触: {ex.Message}", "閿欒", MessageBoxButton.OK, MessageBoxImage.Error);
+            }
+        }
+
+        private void PrevButton_Click(object sender, RoutedEventArgs e)
+        {
+            ShowImage(_currentIndex - 1);
+        }
+
+        private void NextButton_Click(object sender, RoutedEventArgs e)
+        {
+            ShowImage(_currentIndex + 1);
+        }
+        public bool ShowImage_main(string imagePath)
+        {
+            try
+            {
+                // 浣跨敤OpenCvSharp璇诲彇鍥剧墖
+                using (Mat image = Cv2.ImRead(imagePath, ImreadModes.Color))
+                {
+                    if (image.Empty())
+                    {
+                        return false;
+                    }
+
+                    // 浣跨敤Dispatcher纭繚UI绾跨▼鏇存柊
+                    Dispatcher.Invoke(() =>
+                    {
+                        ResultImage.Source = image.ToBitmapSource();
+                        Title = $"鍥剧墖鏌ョ湅:{System.IO.Path.GetFileName(imagePath)}";
+
+                        // 鏇存柊鎸夐挳鐘舵��
+                        PrevButton.IsEnabled = false;
+                        NextButton.IsEnabled = false;
+                    });
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show($"鍔犺浇鍥剧墖澶辫触: {ex.Message}", "閿欒", MessageBoxButton.OK, MessageBoxImage.Error);
+                return false;
+            }
+            return true;
+        }
+    }
+}

--
Gitblit v1.9.3