コード例 #1
0
        public void TestGet()
        {
            IoFilter filterA = new NoopFilter();
            IoFilter filterB = new NoopFilter();
            IoFilter filterC = new NoopFilter();
            IoFilter filterD = new NoopFilter();

            chain.AddFirst("A", filterA);
            chain.AddLast("B", filterB);
            chain.AddBefore("B", "C", filterC);
            chain.AddAfter("A", "D", filterD);

            Assert.AreSame(filterA, chain.Get("A"));
            Assert.AreSame(filterB, chain.Get("B"));
            Assert.AreSame(filterC, chain.Get("C"));
            Assert.AreSame(filterD, chain.Get("D"));
        }
コード例 #2
0
ファイル: IoFilterChainTest.cs プロジェクト: xlg210/Mina.NET
        public void TestGet()
        {
            IoFilter filterA = new NoopFilter();
            IoFilter filterB = new NoopFilter();
            IoFilter filterC = new NoopFilter();
            IoFilter filterD = new NoopFilter();

            chain.AddFirst("A", filterA);
            chain.AddLast("B", filterB);
            chain.AddBefore("B", "C", filterC);
            chain.AddAfter("A", "D", filterD);

            Assert.AreSame(filterA, chain.Get("A"));
            Assert.AreSame(filterB, chain.Get("B"));
            Assert.AreSame(filterC, chain.Get("C"));
            Assert.AreSame(filterD, chain.Get("D"));
        }
コード例 #3
0
        public void TestGet()
        {
            DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder(); // TODO: 初始化为适当的值

            IoFilter filterA = new NoopFilter();
            IoFilter filterB = new NoopFilter();
            IoFilter filterC = new NoopFilter();
            IoFilter filterD = new NoopFilter();

            builder.AddFirst("A", filterA);
            builder.AddLast("B", filterB);
            builder.AddBefore("B", "C", filterC);
            builder.AddAfter("A", "D", filterD);

            Assert.AreSame(filterA, builder.Get("A"));
            Assert.AreSame(filterB, builder.Get("B"));
            Assert.AreSame(filterC, builder.Get("C"));
            Assert.AreSame(filterD, builder.Get("D"));
        }
コード例 #4
0
        public void TestGet()
        {
            DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder(); // TODO: 初始化为适当的值

            IoFilter filterA = new NoopFilter();
            IoFilter filterB = new NoopFilter();
            IoFilter filterC = new NoopFilter();
            IoFilter filterD = new NoopFilter();

            builder.AddFirst("A", filterA);
            builder.AddLast("B", filterB);
            builder.AddBefore("B", "C", filterC);
            builder.AddAfter("A", "D", filterD);

            Assert.AreSame(filterA, builder.Get("A"));
            Assert.AreSame(filterB, builder.Get("B"));
            Assert.AreSame(filterC, builder.Get("C"));
            Assert.AreSame(filterD, builder.Get("D"));
        }
コード例 #5
0
    protected void SaveImage()
    {
        string savedImageFileName = "";
        FormatEncoderParams formatEncoderParams = null;

        object source = null;

        switch (this.ddlSourceType.SelectedIndex)
        {
        case 0:
            // File system
            source = this.imgLoaded.ImageUrl;
            break;

        case 1:
            // Byte array
            source = System.IO.File.ReadAllBytes(Server.MapPath(this.imgLoaded.ImageUrl));
            break;

        case 2:
            // Stream
            source = System.IO.File.OpenRead(Server.MapPath(this.imgLoaded.ImageUrl));
            // Note: The stream will be automatically closed/disposed by the LoadedImage class
            break;
        }
        using (LoadedImage loadedImage = ImageArchiver.LoadImage(source))
        {
            switch (this.ddlImageFormat.SelectedValue)
            {
            case "Auto":
                formatEncoderParams = ImageArchiver.GetDefaultFormatEncoderParams();
                break;

            case "JPEG":
                formatEncoderParams = new JpegFormatEncoderParams(int.Parse(this.txtJpegQuality.Text));
                break;

            case "GIF":
                GifFormatEncoderParams gifFormatEncoderParams = new GifFormatEncoderParams();
                formatEncoderParams = gifFormatEncoderParams;
                gifFormatEncoderParams.QuantizeImage = this.cbGifQuantize.Checked;
                if (this.cbGifQuantize.Checked)
                {
                    gifFormatEncoderParams.MaxColors = int.Parse(this.ddlGifMaxColors.SelectedValue);
                }
                break;

            case "PNG":
                PngFormatEncoderParams pngformatEncoderParams = new PngFormatEncoderParams();
                formatEncoderParams = pngformatEncoderParams;
                pngformatEncoderParams.ConvertToIndexed = this.cbPngConvertToIndex.Checked;
                if (this.cbPngConvertToIndex.Checked)
                {
                    pngformatEncoderParams.MaxColors = int.Parse(this.ddlPngMaxColors.SelectedValue);
                }
                break;
            }

            savedImageFileName = "~/repository/output/Ex_A_103" + formatEncoderParams.FileExtension;

            // IMPORTANT NOTE:  Apply a Noop (No Operation) filter to prevent a known GDI+ problem with transparent images
            // Example: http://forums.asp.net/t/1235100.aspx
            switch (this.ddlOutputType.SelectedIndex)
            {
            case 0:
                // File system
                new NoopFilter().SaveProcessedImageToFileSystem(loadedImage.Image, savedImageFileName, formatEncoderParams);
                break;

            case 1:
                // Byte array
                byte[] imageBytes = new NoopFilter().SaveProcessedImageToByteArray(loadedImage.Image, formatEncoderParams);
                System.IO.File.WriteAllBytes(Server.MapPath(savedImageFileName), imageBytes);
                break;

            case 2:
                // Stream
                using (System.IO.Stream stream = System.IO.File.OpenWrite(Server.MapPath(savedImageFileName)))
                {
                    new NoopFilter().SaveProcessedImageToStream(loadedImage.Image, stream, formatEncoderParams);
                }
                break;
            }
        }

        // Update the displayed image (add a timestamp parameter to the query URL to ensure that the image is reloaded by the browser)
        this.imgSaved.ImageUrl       = savedImageFileName + "?timestamp=" + DateTime.UtcNow.Ticks.ToString();
        this.phOutputPreview.Visible = true;

        // Display extension and size of both files
        this.litLoadedImageFileDetails.Text = System.IO.Path.GetExtension(this.imgLoaded.ImageUrl).ToUpper() + " file (" + (new System.IO.FileInfo(Server.MapPath(this.imgLoaded.ImageUrl))).Length.ToString() + " bytes)";
        this.litSavedImageFileDetails.Text  = System.IO.Path.GetExtension(savedImageFileName).ToUpper() + " file (" + (new System.IO.FileInfo(Server.MapPath(savedImageFileName))).Length.ToString() + " bytes)";
    }
コード例 #6
0
    protected void SaveImage()
    {
        string savedImageFileName = "";
        FormatEncoderParams formatEncoderParams = null;

        object source = null;
        switch (this.ddlSourceType.SelectedIndex)
        {
            case 0:
                // File system
                source = this.imgLoaded.ImageUrl;
                break;
            case 1:
                // Byte array
                source = System.IO.File.ReadAllBytes(Server.MapPath(this.imgLoaded.ImageUrl));
                break;
            case 2:
                // Stream
                source = System.IO.File.OpenRead(Server.MapPath(this.imgLoaded.ImageUrl));
                // Note: The stream will be automatically closed/disposed by the LoadedImage class
                break;
        }
        using (LoadedImage loadedImage = ImageArchiver.LoadImage(source))
        {           
            switch(this.ddlImageFormat.SelectedValue)
            {
                case "Auto":
                    formatEncoderParams = ImageArchiver.GetDefaultFormatEncoderParams();
                    break;
                case "JPEG":
                    formatEncoderParams = new JpegFormatEncoderParams(int.Parse(this.txtJpegQuality.Text));
                    break;
                case "GIF":
                    GifFormatEncoderParams gifFormatEncoderParams = new GifFormatEncoderParams();
                    formatEncoderParams = gifFormatEncoderParams;
                    gifFormatEncoderParams.QuantizeImage = this.cbGifQuantize.Checked;
                    if (this.cbGifQuantize.Checked)
                    {
                        gifFormatEncoderParams.MaxColors = int.Parse(this.ddlGifMaxColors.SelectedValue);
                    }
                    break;
                case "PNG":
                    PngFormatEncoderParams pngformatEncoderParams = new PngFormatEncoderParams();
                    formatEncoderParams = pngformatEncoderParams;
                    pngformatEncoderParams.ConvertToIndexed = this.cbPngConvertToIndex.Checked;
                    if (this.cbPngConvertToIndex.Checked)
                    {
                        pngformatEncoderParams.MaxColors = int.Parse(this.ddlPngMaxColors.SelectedValue);
                    }
                    break;
            }

            savedImageFileName = "~/repository/output/Ex_A_103" + formatEncoderParams.FileExtension;

            // IMPORTANT NOTE:  Apply a Noop (No Operation) filter to prevent a known GDI+ problem with transparent images
            // Example: http://forums.asp.net/t/1235100.aspx
            switch (this.ddlOutputType.SelectedIndex)
            {
                case 0:
                    // File system
                    new NoopFilter().SaveProcessedImageToFileSystem(loadedImage.Image, savedImageFileName, formatEncoderParams);
                    break;
                case 1:
                    // Byte array
                    byte[] imageBytes = new NoopFilter().SaveProcessedImageToByteArray(loadedImage.Image, formatEncoderParams);
                    System.IO.File.WriteAllBytes(Server.MapPath(savedImageFileName), imageBytes);
                    break;
                case 2:
                    // Stream
                    using (System.IO.Stream stream = System.IO.File.OpenWrite(Server.MapPath(savedImageFileName)))
                    {
                        new NoopFilter().SaveProcessedImageToStream(loadedImage.Image, stream, formatEncoderParams);
                    }
                    break;
            }
        }

        // Update the displayed image (add a timestamp parameter to the query URL to ensure that the image is reloaded by the browser)
        this.imgSaved.ImageUrl = savedImageFileName + "?timestamp=" + DateTime.UtcNow.Ticks.ToString();
        this.phOutputPreview.Visible = true;

        // Display extension and size of both files
        this.litLoadedImageFileDetails.Text = System.IO.Path.GetExtension(this.imgLoaded.ImageUrl).ToUpper() + " file (" + (new System.IO.FileInfo(Server.MapPath(this.imgLoaded.ImageUrl))).Length.ToString() + " bytes)";
        this.litSavedImageFileDetails.Text = System.IO.Path.GetExtension(savedImageFileName).ToUpper() + " file (" + (new System.IO.FileInfo(Server.MapPath(savedImageFileName))).Length.ToString() + " bytes)";
    }