-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageProxifier.cs
57 lines (55 loc) · 1.69 KB
/
ImageProxifier.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using ImageProcessor.Processors;
using Microsoft.Win32;
namespace ImageProcessor
{
public class ImageProxifier : Proxifier
{
public override StackPanel GetPanel(Window parent, OptionAttribute attribute, FieldInfo opt, Processor p, Action updater)
{
StackPanel sp = new StackPanel
{
Orientation = Orientation.Horizontal,
};
TextBlock pathText = new TextBlock
{
Text = "待打开图片"
};
Button button = new Button
{
Content = "打开图片"
};
button.Click += (sender, arg) =>
{
var ofp = new OpenFileDialog
{
Filter = "图片(PNG)|*.png|图片(BMP)|*.bmp|图片(JPG)|*.jpg",
DefaultExt = ".png"
};
bool? result = ofp.ShowDialog(parent);
if (result == true)
{
pathText.Text = ofp.FileName;
Bitmap image = new Bitmap(ofp.FileName);
opt.SetValue(p, image);
updater();
}
};
sp.Children.Add(pathText);
sp.Children.Add(button);
return sp;
}
public override IEnumerable<Type> GetProxyTypes()
{
return new Type[] { typeof(System.Drawing.Image), typeof(Bitmap) };
}
}
}