当前位置: 首页>>代码示例>>C#>>正文


C# Size.ScaleToFit方法代码示例

本文整理汇总了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);
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:11,代码来源:MathHelperTests.cs

示例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);
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:11,代码来源:MathHelperTests.cs

示例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
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:12,代码来源:MathHelperTests.cs

示例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
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:11,代码来源:MathHelperTests.cs

示例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);
                }
            }
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:34,代码来源:Images.cs


注:本文中的System.Drawing.Size.ScaleToFit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。