aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Drawing/ImageSize.cs
blob: c2b0291bdb03d90b0fd435a0204b8fa08bc48501 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System.Globalization;

namespace MediaBrowser.Model.Drawing
{
    /// <summary>
    /// Struct ImageSize
    /// </summary>
    public struct ImageSize
    {
        private double _height;
        private double _width;

        /// <summary>
        /// Gets or sets the height.
        /// </summary>
        /// <value>The height.</value>
        public double Height
        {
            get
            {
                return _height;
            }
            set
            {
                _height = value;
            }
        }

        /// <summary>
        /// Gets or sets the width.
        /// </summary>
        /// <value>The width.</value>
        public double Width
        {
            get { return _width; }
            set { _width = value; }
        }

        public bool Equals(ImageSize size)
        {
            return Width.Equals(size.Width) && Height.Equals(size.Height);
        }

        public override string ToString()
        {
            return string.Format("{0}-{1}", Width, Height);
        }

        public ImageSize(string value)
        {
            _width = 0;

            _height = 0;

            ParseValue(value);
        }

        public ImageSize(int width, int height)
        {
            _width = width;
            _height = height;
        }

        public ImageSize(double width, double height)
        {
            _width = width;
            _height = height;
        }

        private void ParseValue(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                string[] parts = value.Split('-');

                if (parts.Length == 2)
                {
                    double val;

                    if (double.TryParse(parts[0], NumberStyles.Any, CultureInfo.InvariantCulture, out val))
                    {
                        _width = val;
                    }

                    if (double.TryParse(parts[1], NumberStyles.Any, CultureInfo.InvariantCulture, out val))
                    {
                        _height = val;
                    }
                }
            }
        }
    }
}