private WpfSize ConvertSize(SizeF size, WpfSize availableSize, out WpfSize renderSize) { double ratio; if (Orientation == Orientation.Vertical) { ratio = availableSize.Width / size.Width; } else { ratio = availableSize.Height / size.Height; } if (!double.IsNaN(MaxScale)) { ratio = Math.Min(ratio, MaxScale); } var newSize = new WpfSize((int)(size.Width * ratio), (int)(size.Height * ratio)); renderSize = BitmapUtility.ConvertSize(newSize); return(newSize); }