프로젝트

일반

사용자정보

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

markus / ImageComparer / ComparerTestWPF / MainWindow.xaml.cs @ 2a2e72c2

이력 | 보기 | 이력해설 | 다운로드 (5.54 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 result2 = imageComparer.CompareDrawRects(target, original, new System.Drawing.Size(20, 20));
72
                //TargetSource = imageComparer.CreateBitmapSourceFromBitmap(result2);
73
                //result2.Dispose();
74
                //result2 = null;
75
                
76
                original.Dispose();
77
                target.Dispose();
78
            }
79

    
80
            if (bitmapSource != null)
81
            {
82
                ImageView imageView = new ImageView(bitmapSource);
83

    
84
                imageView.Show();
85
            }
86
            else
87
            {
88
                MessageBox.Show("bitmapSource is null");
89
            }
90

    
91

    
92
            //ImageView imageView2 = new ImageView(TargetSource);
93

    
94
            //imageView2.Show();
95
        }
96

    
97
        private async void btTask_Click(object sender, RoutedEventArgs e)
98
        {
99
            BitmapSource bitmapSource = null;
100
            BitmapSource TargetSource = null;
101

    
102
            using (Markus.Image.ImageCompare imageComparer = new Markus.Image.ImageCompare())
103
            {
104

    
105
                var original = new System.Drawing.Bitmap(TxtOriginalImage.Text);
106
                var target = new System.Drawing.Bitmap(TxtTargetImage.Text);
107

    
108
                var result = await imageComparer.CompareReturnRectsAsync(original, target, new System.Drawing.Size(20, 20));
109
                // bitmapSource = imageComparer.CreateWriteableBitmapFromBitmap(result);
110

    
111
                lstView.ItemsSource = result;
112

    
113
                var original2 = new System.Drawing.Bitmap(TxtOriginalImage.Text);
114
                var target2 = new System.Drawing.Bitmap(TxtTargetImage.Text);
115

    
116

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

    
119
                lstView2.ItemsSource = result2;
120
                //TargetSource = imageComparer.CreateWriteableBitmapFromBitmap(result2);
121

    
122
                original.Dispose();
123
                target.Dispose();
124
            }
125
            
126

    
127
            //ImageView imageView = new ImageView(bitmapSource);
128

    
129
            //imageView.Show();
130

    
131
            //ImageView imageView2 = new ImageView(TargetSource);
132

    
133
            //imageView2.Show();
134
        }
135

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

    
142

    
143

    
144

    
145

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

    
150
                MessageBox.Show(rects.Count().ToString());
151

    
152
                var result = await imageComparer.CompareDrawRectsAsync(TxtOriginalImage.Text
153
                    , TxtTargetImage.Text, new System.Drawing.Size(20, 20));
154

    
155
                bitmapSource = result;
156

    
157
                //lstView.ItemsSource = result;
158

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

    
162
                //lstView2.ItemsSource = result2;
163
                //TargetSource = imageComparer.CreateWriteableBitmapFromBitmap(result2);
164

    
165
            }
166

    
167
            ImageView imageView = new ImageView(bitmapSource);
168

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