프로젝트

일반

사용자정보

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

markus / KCOM / Controls / DecodeImage.cs @ 09b40aad

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

1
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
   // [TemplatePart(Name = PART_IMAGE, Type = typeof(Image))]
15
    public class ScaleDecodeImage : System.Windows.Controls.Control
16
    {
17
       // private const string PART_IMAGE = "PART_IMAGE";
18
        //private Image ImageControl;
19

    
20
        public override void OnApplyTemplate()
21
        {
22
            base.OnApplyTemplate();
23

    
24
            //ImageControl = GetTemplateChild(PART_IMAGE) as Image;
25
        }
26

    
27

    
28
        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
        public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
39
                    "Source", typeof(BitmapImage), typeof(ScaleDecodeImage), new PropertyMetadata(new PropertyChangedCallback(SourcePropertyChaged)));
40

    
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
            if (owner != null)
53
            {
54
                if (e.NewValue != null)
55
                {
56
                    owner.ViewSource = (BitmapImage)e.NewValue;
57
                    owner.Scale = 1.0;
58
                }
59
            }
60
        }
61

    
62
        public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register(
63
                    "Scale", typeof(double), typeof(ScaleDecodeImage), new PropertyMetadata(0.0, new PropertyChangedCallback(ScalePropertyChaged)));
64

    
65

    
66
        public double Scale
67
        {
68
            get => (double)GetValue(ScaleProperty);
69
            set => SetValue(ScaleProperty, value);
70
        }
71

    
72
        private static void ScalePropertyChaged(DependencyObject d, DependencyPropertyChangedEventArgs e)
73
        {
74
            var owner = d as ScaleDecodeImage;
75

    
76
            if (owner != null)
77
            {
78
                var value = owner.Scale;
79
                System.Windows.Media.Imaging.BitmapImage image = owner.Source.Clone();
80

    
81
                image.DecodePixelWidth = (int)(image.PixelWidth * value);
82
                image.DecodePixelHeight = (int)(image.PixelHeight * value);
83

    
84
                owner.ViewSource = image;
85
            }
86
        }
87
    }
88
}
클립보드 이미지 추가 (최대 크기: 500 MB)