markus / KCOM / Controls / DecodeImage.cs @ 09b40aad
이력 | 보기 | 이력해설 | 다운로드 (2.75 KB)
1 | 92442e4a | taeseongkim | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | |||
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.Media; |
||
10 | using System.Windows.Media.Imaging; |
||
11 | |||
12 | namespace KCOM.Controls |
||
13 | { |
||
14 | 09b40aad | taeseongkim | // [TemplatePart(Name = PART_IMAGE, Type = typeof(Image))] |
15 | 92442e4a | taeseongkim | public class ScaleDecodeImage : System.Windows.Controls.Control |
16 | { |
||
17 | 09b40aad | taeseongkim | // private const string PART_IMAGE = "PART_IMAGE"; |
18 | //private Image ImageControl; |
||
19 | 92442e4a | taeseongkim | |
20 | public override void OnApplyTemplate() |
||
21 | { |
||
22 | base.OnApplyTemplate(); |
||
23 | |||
24 | 09b40aad | taeseongkim | //ImageControl = GetTemplateChild(PART_IMAGE) as Image; |
25 | 92442e4a | taeseongkim | } |
26 | |||
27 | |||
28 | 09b40aad | taeseongkim | public static readonly DependencyProperty ViewSourceProperty = DependencyProperty.Register( |
29 | "ViewSource", typeof(BitmapImage), typeof(ScaleDecodeImage)); |
||
30 | |||
31 | |||
32 | public BitmapImage ViewSource |
||
33 | { |
||
34 | get => (BitmapImage)GetValue(ViewSourceProperty); |
||
35 | set => SetValue(ViewSourceProperty, value); |
||
36 | } |
||
37 | |||
38 | 92442e4a | taeseongkim | public static readonly DependencyProperty SourceProperty = DependencyProperty.Register( |
39 | 09b40aad | taeseongkim | "Source", typeof(BitmapImage), typeof(ScaleDecodeImage), new PropertyMetadata(new PropertyChangedCallback(SourcePropertyChaged))); |
40 | 92442e4a | taeseongkim | |
41 | |||
42 | public BitmapImage Source |
||
43 | { |
||
44 | get => (BitmapImage)GetValue(SourceProperty); |
||
45 | set => SetValue(SourceProperty, value); |
||
46 | } |
||
47 | |||
48 | private static void SourcePropertyChaged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
||
49 | { |
||
50 | var owner = d as ScaleDecodeImage; |
||
51 | |||
52 | 09b40aad | taeseongkim | if (owner != null) |
53 | 92442e4a | taeseongkim | { |
54 | 09b40aad | taeseongkim | if (e.NewValue != null) |
55 | { |
||
56 | owner.ViewSource = (BitmapImage)e.NewValue; |
||
57 | owner.Scale = 1.0; |
||
58 | } |
||
59 | 92442e4a | taeseongkim | } |
60 | } |
||
61 | |||
62 | public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register( |
||
63 | 09b40aad | taeseongkim | "Scale", typeof(double), typeof(ScaleDecodeImage), new PropertyMetadata(0.0, new PropertyChangedCallback(ScalePropertyChaged))); |
64 | 92442e4a | taeseongkim | |
65 | |||
66 | public double Scale |
||
67 | { |
||
68 | get => (double)GetValue(ScaleProperty); |
||
69 | set => SetValue(ScaleProperty, value); |
||
70 | } |
||
71 | |||
72 | 09b40aad | taeseongkim | private static void ScalePropertyChaged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
73 | 92442e4a | taeseongkim | { |
74 | var owner = d as ScaleDecodeImage; |
||
75 | |||
76 | if (owner != null) |
||
77 | { |
||
78 | 09b40aad | taeseongkim | var value = owner.Scale; |
79 | System.Windows.Media.Imaging.BitmapImage image = owner.Source.Clone(); |
||
80 | 92442e4a | taeseongkim | |
81 | 09b40aad | taeseongkim | image.DecodePixelWidth = (int)(image.PixelWidth * value); |
82 | image.DecodePixelHeight = (int)(image.PixelHeight * value); |
||
83 | 92442e4a | taeseongkim | |
84 | 09b40aad | taeseongkim | owner.ViewSource = image; |
85 | 92442e4a | taeseongkim | } |
86 | } |
||
87 | } |
||
88 | } |