jellyfin/MediaBrowser.Model/Drawing/ImageSize.cs

86 lines
2.0 KiB
C#
Raw Normal View History

2018-12-27 23:27:57 +00:00
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 => _height;
set => _height = value;
2018-12-27 23:27:57 +00:00
}
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>The width.</value>
public double Width
{
get => _width;
set => _width = value;
2018-12-27 23:27:57 +00:00
}
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)
{
if (double.TryParse(parts[0], NumberStyles.Any, CultureInfo.InvariantCulture, out var val))
2018-12-27 23:27:57 +00:00
{
_width = val;
}
if (double.TryParse(parts[1], NumberStyles.Any, CultureInfo.InvariantCulture, out val))
{
_height = val;
}
}
}
}
}
}