From 883575893b3f4a4224f920e8c143a9edefca13e4 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 26 Jan 2019 13:16:47 +0100 Subject: Change image dimentions from double to int Rename ImageSize -> ImageDimensions --- MediaBrowser.Model/Drawing/DrawingUtils.cs | 42 +++++++++++------------------- 1 file changed, 15 insertions(+), 27 deletions(-) (limited to 'MediaBrowser.Model/Drawing/DrawingUtils.cs') diff --git a/MediaBrowser.Model/Drawing/DrawingUtils.cs b/MediaBrowser.Model/Drawing/DrawingUtils.cs index fbd074218..9fe85512f 100644 --- a/MediaBrowser.Model/Drawing/DrawingUtils.cs +++ b/MediaBrowser.Model/Drawing/DrawingUtils.cs @@ -1,3 +1,5 @@ +using System; + namespace MediaBrowser.Model.Drawing { /// @@ -14,27 +16,25 @@ namespace MediaBrowser.Model.Drawing /// A max fixed width, if desired /// A max fixed height, if desired /// A new size object - public static ImageSize Resize(ImageSize size, - double width, - double height, - double maxWidth, - double maxHeight) + public static ImageDimensions Resize(ImageDimensions size, + int width, + int height, + int maxWidth, + int maxHeight) { - double newWidth = size.Width; - double newHeight = size.Height; + int newWidth = size.Width; + int newHeight = size.Height; if (width > 0 && height > 0) { newWidth = width; newHeight = height; } - else if (height > 0) { newWidth = GetNewWidth(newHeight, newWidth, height); newHeight = height; } - else if (width > 0) { newHeight = GetNewHeight(newHeight, newWidth, width); @@ -53,7 +53,7 @@ namespace MediaBrowser.Model.Drawing newWidth = maxWidth; } - return new ImageSize { Width = newWidth, Height = newHeight }; + return new ImageDimensions(newWidth, newHeight); } /// @@ -62,15 +62,9 @@ namespace MediaBrowser.Model.Drawing /// Height of the current. /// Width of the current. /// The new height. - /// System.Double. - private static double GetNewWidth(double currentHeight, double currentWidth, double newHeight) - { - double scaleFactor = newHeight; - scaleFactor /= currentHeight; - scaleFactor *= currentWidth; - - return scaleFactor; - } + /// the new width + private static int GetNewWidth(int currentHeight, int currentWidth, int newHeight) + => Convert.ToInt32((double)newHeight / currentHeight * currentWidth); /// /// Gets the new height. @@ -79,13 +73,7 @@ namespace MediaBrowser.Model.Drawing /// Width of the current. /// The new width. /// System.Double. - private static double GetNewHeight(double currentHeight, double currentWidth, double newWidth) - { - double scaleFactor = newWidth; - scaleFactor /= currentWidth; - scaleFactor *= currentHeight; - - return scaleFactor; - } + private static int GetNewHeight(int currentHeight, int currentWidth, int newWidth) + => Convert.ToInt32((double)newWidth / currentWidth * currentHeight); } } -- cgit v1.2.3