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


C# WebImage.Save方法代码示例

本文整理汇总了C#中WebImage.Save方法的典型用法代码示例。如果您正苦于以下问题:C# WebImage.Save方法的具体用法?C# WebImage.Save怎么用?C# WebImage.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WebImage的用法示例。


在下文中一共展示了WebImage.Save方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveUsesOriginalFormatForStreamsWhenNoFormatIsSpecified

        public void SaveUsesOriginalFormatForStreamsWhenNoFormatIsSpecified()
        {
            // Arrange
            // Use rooted path so we by pass using HttpContext
            var specifiedOutputFile = @"x:\some-dir\foo.jpg";
            string actualOutputFile = null;
            Action<string, byte[]> saveAction = (fileName, content) => { actualOutputFile = fileName; };

            // Act
            WebImage image = new WebImage(_PngImageBytes);
            image.Save(GetContext(), saveAction, filePath: specifiedOutputFile, imageFormat: null, forceWellKnownExtension: true);

            // Assert
            Assert.Equal(Path.GetExtension(actualOutputFile), ".png");
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:15,代码来源:WebImageTest.cs

示例2: SaveThrowsWhenPathIsNull

        public void SaveThrowsWhenPathIsNull()
        {
            Action<string, byte[]> saveAction = (path, content) => { };

            // this constructor will not set path
            byte[] originalContent = _BmpImageBytes;
            WebImage image = new WebImage(originalContent);

            Assert.ThrowsArgumentNullOrEmptyString(
                () => image.Save(GetContext(), saveAction, filePath: null, imageFormat: null, forceWellKnownExtension: true),
                "filePath");
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:12,代码来源:WebImageTest.cs

示例3: SaveThrowsWhenPathIsEmpty

        public void SaveThrowsWhenPathIsEmpty()
        {
            Action<string, byte[]> saveAction = (path, content) => { };
            WebImage image = new WebImage(_BmpImageBytes);

            Assert.ThrowsArgumentNullOrEmptyString(
                () => image.Save(GetContext(), saveAction, filePath: String.Empty, imageFormat: null, forceWellKnownExtension: true),
                "filePath");
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:9,代码来源:WebImageTest.cs

示例4: SaveKeepsNameIfFormatIsUnchanged

        public void SaveKeepsNameIfFormatIsUnchanged()
        {
            // Arrange
            string imagePath = @"x:\images\foo.jpg";
            var context = GetContext();

            // Act
            WebImage image = new WebImage(context, _ => _JpgImageBytes, imagePath);

            image.Save(context, (_, __) => { }, imagePath, "jpg", forceWellKnownExtension: true);

            // Assert
            Assert.Equal(@"x:\images\foo.jpg", image.FileName);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:14,代码来源:WebImageTest.cs

示例5: SaveOverwritesExistingFile

        public void SaveOverwritesExistingFile()
        {
            Action<string, byte[]> saveAction = (path, content) => { };

            WebImage image = new WebImage(_BmpImageBytes);
            string newFileName = @"x:\newImage.bmp";

            image.Save(GetContext(), saveAction, newFileName, imageFormat: null, forceWellKnownExtension: true);

            image.RotateLeft();
            // just verify this does not throw
            image.Save(GetContext(), saveAction, newFileName, imageFormat: null, forceWellKnownExtension: true);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:13,代码来源:WebImageTest.cs

示例6: SaveUpdatesFileNameOfWebImageWhenForcingWellKnownExtension

        public void SaveUpdatesFileNameOfWebImageWhenForcingWellKnownExtension()
        {
            // Arrange
            var context = GetContext();

            // Act
            WebImage image = new WebImage(context, _ => _JpgImageBytes, @"c:\images\foo.jpg");

            image.Save(context, (_, __) => { }, @"x:\1.exe", "jpg", forceWellKnownExtension: true);

            // Assert
            Assert.Equal(@"x:\1.exe.jpeg", image.FileName);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:13,代码来源:WebImageTest.cs

示例7: SaveUpdatesFileNameOfWebImageWhenFormatChanges

        public void SaveUpdatesFileNameOfWebImageWhenFormatChanges()
        {
            // Arrange
            string imagePath = @"x:\images\foo.jpg";
            var context = GetContext();

            // Act
            WebImage image = new WebImage(context, _ => _JpgImageBytes, imagePath);

            image.Save(context, (_, __) => { }, imagePath, "png", forceWellKnownExtension: true);

            // Assert
            Assert.Equal(@"x:\images\foo.jpg.png", image.FileName);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:14,代码来源:WebImageTest.cs

示例8: ResizePreservesFormat

        public void ResizePreservesFormat()
        {
            // Arrange
            WebImage image = new WebImage(_PngImageBytes);
            MemoryStream output = null;
            Action<string, byte[]> saveAction = (_, content) => { output = new MemoryStream(content); };

            // Act
            image.Resize(200, 100, preserveAspectRatio: true, preventEnlarge: true);

            // Assert
            Assert.Equal(image.ImageFormat, "png");
            image.Save(GetContext(), saveAction, @"x:\1.png", null, false);

            using (Image modified = Image.FromStream(output))
            {
                Assert.Equal(ImageFormat.Png, modified.RawFormat);
            }
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:19,代码来源:WebImageTest.cs

示例9: ResizePreservesResolution

        public void ResizePreservesResolution()
        {
            MemoryStream output = null;
            Action<string, byte[]> saveAction = (_, content) => { output = new MemoryStream(content); };

            WebImage image = new WebImage(_PngImageBytes);

            image.Resize(100, 50, preserveAspectRatio: true, preventEnlarge: true);

            image.Save(GetContext(), saveAction, @"x:\ResizePreservesResolution.jpg", "jpeg", forceWellKnownExtension: true);
            using (Image original = Image.FromStream(new MemoryStream(_PngImageBytes)))
            {
                using (Image modified = Image.FromStream(output))
                {
                    Assert.Equal(original.HorizontalResolution, modified.HorizontalResolution);
                    Assert.Equal(original.VerticalResolution, modified.VerticalResolution);
                }
            }
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:19,代码来源:WebImageTest.cs

示例10: SaveUsesInitialFormatWhenNoFormatIsSpecified

        public void SaveUsesInitialFormatWhenNoFormatIsSpecified()
        {
            // Arrange
            string savePath = @"x:\some-dir\image.png";
            MemoryStream stream = null;
            Action<string, byte[]> saveAction = (path, content) => { stream = new MemoryStream(content); };
            var image = new WebImage(_PngImageBytes);

            // Act 
            image.FlipVertical().FlipHorizontal();

            // Assert
            image.Save(GetContext(), saveAction, savePath, imageFormat: null, forceWellKnownExtension: true);

            using (Image savedImage = Image.FromStream(stream))
            {
                Assert.Equal(savedImage.RawFormat, ImageFormat.Png);
            }
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:19,代码来源:WebImageTest.cs

示例11: SaveDoesNotModifyExtensionWhenForceCorrectExtensionRenameIsCleared

        public void SaveDoesNotModifyExtensionWhenForceCorrectExtensionRenameIsCleared()
        {
            // Arrange
            // Use rooted path so we by pass using HttpContext
            var specifiedOutputFile = @"x:\some-dir\foo.exe";
            string actualOutputFile = null;
            Action<string, byte[]> saveAction = (fileName, content) => { actualOutputFile = fileName; };

            // Act
            WebImage image = new WebImage(_BmpImageBytes);
            image.Save(GetContext(), saveAction, filePath: specifiedOutputFile, imageFormat: "jpg", forceWellKnownExtension: false);

            // Assert
            Assert.Equal(specifiedOutputFile, actualOutputFile);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:15,代码来源:WebImageTest.cs

示例12: SaveAppendsExtensionBasedOnFormatWhenForceExtensionIsSet

        public void SaveAppendsExtensionBasedOnFormatWhenForceExtensionIsSet()
        {
            // Arrange
            // Use rooted path so we by pass using HttpContext
            var specifiedOutputFile = @"x:\some-dir\foo";
            string actualOutputFile = null;
            Action<string, byte[]> saveAction = (fileName, content) => { actualOutputFile = fileName; };

            // Act
            WebImage image = new WebImage(_BmpImageBytes);
            image.Save(GetContext(), saveAction, filePath: specifiedOutputFile, imageFormat: "jpg", forceWellKnownExtension: true);

            // Assert
            Assert.Equal(".jpeg", Path.GetExtension(actualOutputFile));
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:15,代码来源:WebImageTest.cs


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