當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。