ImageSize.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Globalization;
  2. namespace MediaBrowser.Model.Drawing
  3. {
  4. /// <summary>
  5. /// Struct ImageSize
  6. /// </summary>
  7. public struct ImageSize
  8. {
  9. private double _height;
  10. private double _width;
  11. /// <summary>
  12. /// Gets or sets the height.
  13. /// </summary>
  14. /// <value>The height.</value>
  15. public double Height
  16. {
  17. get
  18. {
  19. return _height;
  20. }
  21. set
  22. {
  23. _height = value;
  24. }
  25. }
  26. /// <summary>
  27. /// Gets or sets the width.
  28. /// </summary>
  29. /// <value>The width.</value>
  30. public double Width
  31. {
  32. get { return _width; }
  33. set { _width = value; }
  34. }
  35. public bool Equals(ImageSize size)
  36. {
  37. return Width.Equals(size.Width) && Height.Equals(size.Height);
  38. }
  39. public override string ToString()
  40. {
  41. return string.Format("{0}-{1}", Width, Height);
  42. }
  43. public ImageSize(string value)
  44. {
  45. _width = 0;
  46. _height = 0;
  47. ParseValue(value);
  48. }
  49. public ImageSize(int width, int height)
  50. {
  51. _width = width;
  52. _height = height;
  53. }
  54. public ImageSize(double width, double height)
  55. {
  56. _width = width;
  57. _height = height;
  58. }
  59. private void ParseValue(string value)
  60. {
  61. if (!string.IsNullOrEmpty(value))
  62. {
  63. string[] parts = value.Split('-');
  64. if (parts.Length == 2)
  65. {
  66. double val;
  67. if (double.TryParse(parts[0], NumberStyles.Any, CultureInfo.InvariantCulture, out val))
  68. {
  69. _width = val;
  70. }
  71. if (double.TryParse(parts[1], NumberStyles.Any, CultureInfo.InvariantCulture, out val))
  72. {
  73. _height = val;
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }