ImageSize.cs 1.9 KB

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