프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / ComparerTestWPF / MainWindow.xaml.cs @ c1659a98

이력 | 보기 | 이력해설 | 다운로드 (5.66 KB)

1
using Microsoft.Win32;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7
using System.Windows;
8
using System.Windows.Controls;
9
using System.Windows.Data;
10
using System.Windows.Documents;
11
using System.Windows.Input;
12
using System.Windows.Media;
13
using System.Windows.Media.Imaging;
14
using System.Windows.Navigation;
15
using System.Windows.Shapes;
16

    
17
namespace ComparerTestWPF
18
{
19
    /// <summary>
20
    /// MainWindow.xaml에 대한 상호 작용 논리
21
    /// </summary>
22
    public partial class MainWindow : Window
23
    {
24
        public MainWindow()
25
        {
26
            InitializeComponent();
27
        }
28

    
29

    
30
        private void btFindOriginalFile_click(object sender, RoutedEventArgs e)
31
        {
32
            TxtOriginalImage.Text = FileOpen();
33
        }
34

    
35
        private void btFindTargetFile_click(object sender, RoutedEventArgs e)
36
        {
37
            TxtTargetImage.Text = FileOpen();
38
        }
39

    
40
        private string FileOpen()
41
        {
42
            string result = null;
43

    
44
            OpenFileDialog openFileDialog = new OpenFileDialog();
45

    
46
            openFileDialog.Filter = "Image Files|*.png;*.jpg;*.bmp";
47

    
48
                if (openFileDialog.ShowDialog() == true)
49
                    result = openFileDialog.FileName;
50
                else
51
                    result = null;
52

    
53
            return result;
54
        }
55

    
56

    
57
        private void btNoneTask_Click(object sender, RoutedEventArgs e)
58
        {
59
            BitmapSource bitmapSource = null;
60
            BitmapSource TargetSource = null;
61

    
62
            using (Markus.Image.ImageCompare imageCompare = new Markus.Image.ImageCompare())
63
            {
64
                var original = new System.Drawing.Bitmap(TxtOriginalImage.Text,true);
65
                var target = new System.Drawing.Bitmap(TxtTargetImage.Text, true);
66

    
67
                var result = imageCompare.CompareDrawRects(original, target, new System.Drawing.Size(20, 20));
68
                
69
                bitmapSource = imageCompare.CreateWriteableBitmapFromBitmap(result);
70

    
71
                var original2= new System.Drawing.Bitmap(TxtOriginalImage.Text, true);
72
                var target2 = new System.Drawing.Bitmap(TxtTargetImage.Text, true);
73

    
74

    
75
                var result2 = imageCompare.CompareDrawRects(target2, original2, new System.Drawing.Size(20, 20));
76
                TargetSource = imageCompare.CreateBitmapSourceFromBitmap(result2);
77
            
78
                original.Dispose();
79
                target.Dispose();
80
            }
81

    
82
            if (bitmapSource != null && TargetSource != null)
83
            {
84
                ImageView imageView = new ImageView(bitmapSource);
85

    
86
                imageView.Show();
87

    
88

    
89
                ImageView imageView2 = new ImageView(TargetSource);
90

    
91
                imageView2.Show();
92
            }
93
            else
94
            {
95
                MessageBox.Show("bitmapSource is null");
96
            }
97

    
98
        }
99

    
100
        private async void btTask_Click(object sender, RoutedEventArgs e)
101
        {
102
            BitmapSource bitmapSource = null;
103
            BitmapSource TargetSource = null;
104

    
105
            using (Markus.Image.ImageCompare imageComparer = new Markus.Image.ImageCompare())
106
            {
107

    
108
                var original = new System.Drawing.Bitmap(TxtOriginalImage.Text);
109
                var target = new System.Drawing.Bitmap(TxtTargetImage.Text);
110

    
111
                var result = await imageComparer.CompareReturnRectsAsync(original, target, new System.Drawing.Size(20, 20));
112
                // bitmapSource = imageComparer.CreateWriteableBitmapFromBitmap(result);
113

    
114
                lstView.ItemsSource = result;
115

    
116
                var original2 = new System.Drawing.Bitmap(TxtOriginalImage.Text);
117
                var target2 = new System.Drawing.Bitmap(TxtTargetImage.Text);
118

    
119

    
120
                var result2 = await imageComparer.CompareReturnRectsAsync(target2, original2, new System.Drawing.Size(20, 20));
121

    
122
                lstView2.ItemsSource = result2;
123
                //TargetSource = imageComparer.CreateWriteableBitmapFromBitmap(result2);
124

    
125
                original.Dispose();
126
                target.Dispose();
127
            }
128
            
129

    
130
            //ImageView imageView = new ImageView(bitmapSource);
131

    
132
            //imageView.Show();
133

    
134
            //ImageView imageView2 = new ImageView(TargetSource);
135

    
136
            //imageView2.Show();
137
        }
138

    
139
        private async void btTaskUri_Click(object sender, RoutedEventArgs e)
140
        {
141
            BitmapSource bitmapSource = null;
142
            //http://10.10.130.12:8977/TileSource/12345_Tile/24771794/2477179440/1.png
143
            //http://10.10.130.12:8977/TileSource/12345_Tile/24771794/2477179438/1.png
144

    
145

    
146

    
147

    
148

    
149
            using (Markus.Image.ImageCompare imageComparer = new Markus.Image.ImageCompare())
150
            {
151
                var rects = imageComparer.CompareReturnRects(TxtOriginalImage.Text, TxtTargetImage.Text, new System.Drawing.Size(20, 20));
152

    
153
                MessageBox.Show(rects.Count().ToString());
154

    
155
                var result = await imageComparer.CompareDrawRectsAsync(TxtOriginalImage.Text
156
                    , TxtTargetImage.Text, new System.Drawing.Size(20, 20));
157

    
158
                bitmapSource = result;
159

    
160
                //lstView.ItemsSource = result;
161

    
162
                //var result2 = await imageComparer.CompareReturnRectsAsync("http://192.168.0.67:5977/TileSource/000000_Tile/110001/11000101/1.png"
163
                //    , "http://192.168.0.67:5977/TileSource/000000_Tile/110001/11000102/1.png", new System.Drawing.Size(20, 20));
164

    
165
                //lstView2.ItemsSource = result2;
166
                //TargetSource = imageComparer.CreateWriteableBitmapFromBitmap(result2);
167

    
168
            }
169

    
170
            ImageView imageView = new ImageView(bitmapSource);
171

    
172
            imageView.Show();
173
        }
174
    }
175
}
클립보드 이미지 추가 (최대 크기: 500 MB)