本文整理汇总了C#中System.Drawing.Size.ScaleToFit方法的典型用法代码示例。如果您正苦于以下问题:C# Size.ScaleToFit方法的具体用法?C# Size.ScaleToFit怎么用?C# Size.ScaleToFit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Size
的用法示例。
在下文中一共展示了Size.ScaleToFit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScaleToFit_ScaledToSameAspectRatio_ScalesExactlyToMaxSize
public void ScaleToFit_ScaledToSameAspectRatio_ScalesExactlyToMaxSize()
{
// arrange
var original = new Size(8, 4); // aspect = 2.00
// act
Size resized = original.ScaleToFit(new Size(4, 2));
// assert
Assert.AreEqual(new Size(4, 2), resized);
}
示例2: ScaleToFit_WithImageAlreadyFitting_ReturnsOriginalImage
public void ScaleToFit_WithImageAlreadyFitting_ReturnsOriginalImage()
{
// arrange
var original = new Size(8, 4); // aspect = 2.00
// act
Size resized = original.ScaleToFit(new Size(12, 15));
// assert
Assert.AreEqual(new Size(8, 4), resized);
}
示例3: ScaleToFit_WithImageHavingAspectRatioLessThanOneScaledToAspectRatioGreaterThanOne_ScalesCorrectly
public void ScaleToFit_WithImageHavingAspectRatioLessThanOneScaledToAspectRatioGreaterThanOne_ScalesCorrectly()
{
// arrange
var original = new Size(5, 7); // aspect = 0.71
var maxSize = new Size(4, 3); // aspect = 1.33
// act
Size resized = original.ScaleToFit(maxSize);
// assert
Assert.AreEqual(new Size(2, 3), resized); // aspect = 0.67
}
示例4: ScaleToFit_WithRealisticImageSizes_ScalesProperly
public void ScaleToFit_WithRealisticImageSizes_ScalesProperly()
{
// arrange
var original = new Size(1352, 879);
// act
Size resized = original.ScaleToFit(640, 480);
// assert
Assert.AreEqual(new Size(640, 416), resized); // aspect = 2
}
示例5: MakeAlbumImages
/// <summary>
/// Saves two images. A normal image for the web site and then a thumbnail.
/// </summary>
/// <param name="image">Original image to process.</param>
public static void MakeAlbumImages(Image image)
{
if(image == null)
{
throw new ArgumentNullException("image");
}
// Indexed GIFs can cause issues.
using(System.Drawing.Image originalImage = GraphicsHelper.FromFilePathAsUnindexedImage(image.OriginalFilePath))
{
var originalSize = new Size(originalImage.Width, originalImage.Height);
/// TODO: make new sizes configurations.
// New Display Size
Size displaySize = originalSize.ScaleToFit(Config.Settings.GalleryImageMaxWidth, Config.Settings.GalleryImageMaxHeight);
image.Height = displaySize.Height;
image.Width = displaySize.Width;
using(System.Drawing.Image displayImage = originalImage.GetResizedImage(displaySize))
{
displayImage.Save(image.ResizedFilePath, ImageFormat.Jpeg);
}
// smaller thumbnail
Size thumbSize = originalSize.ScaleToFit(Config.Settings.GalleryImageThumbnailWidth, Config.Settings.GalleryImageThumbnailHeight);
using(System.Drawing.Image thumbnailImage = originalImage.GetResizedImage(thumbSize))
{
thumbnailImage.Save(image.ThumbNailFilePath, ImageFormat.Jpeg);
}
}
}