本文整理汇总了C#中Size.ToRational方法的典型用法代码示例。如果您正苦于以下问题:C# Size.ToRational方法的具体用法?C# Size.ToRational怎么用?C# Size.ToRational使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Size
的用法示例。
在下文中一共展示了Size.ToRational方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateMaxSize
/// <summary>
/// Returns the maximium dimensions of an image w/ a specific aspect
/// </summary>
public static Size CalculateMaxSize(Size sourceSize, Rational aspect)
{
var targetAspect = aspect.ToDouble();
var currentAspect = sourceSize.ToRational().ToDouble();
if (currentAspect > targetAspect) // Shrink the width
{
int newWidth = (int)(sourceSize.Height * targetAspect);
return new Size(newWidth, sourceSize.Height);
}
else if (currentAspect < targetAspect) // Shrink the height
{
int newHeight = (int)(sourceSize.Width / targetAspect);
return new Size(sourceSize.Width, newHeight);
}
else // The source and target aspect are the same
{
return sourceSize;
}
}
示例2: CalculateScaledSize
public static Size CalculateScaledSize(Size sourceSize, Size maxSize, ScaleMode scaleMode = ScaleMode.None)
{
var aspect = sourceSize.ToRational();
var calculatedSize = CalculateMaxSize(maxSize, aspect);
// If we are not stretching the image, make sure the result is not bigger then the sourceSize
if (scaleMode == ScaleMode.None)
{
if (calculatedSize.Height > sourceSize.Height || calculatedSize.Width > sourceSize.Width)
{
calculatedSize = CalculateMaxSize(sourceSize, aspect);
}
}
return calculatedSize;
}