protected void ProcessImage()
    {
        // Setup the source file name and the output file name
        string sourceImageFileName = this.imgSource.ImageUrl;
        string outputImageFileName = "~/repository/output/Ex_A_101.jpg";

        switch (this.ddlFilter.SelectedIndex)
        {
        case 0:
            // Fixed Size Crop Constraint
            int cropWidth  = 160;
            int cropHeight = 350;
            new FixedCropConstraint(cropWidth, cropHeight).SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
            break;

        case 1:
            // Scaled Resize Constraint
            int maxWidth  = 160;
            int maxHeight = 350;
            new ScaledResizeConstraint(maxWidth, maxHeight).SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
            break;

        case 2:
            // Grayscale Color Filter
            DefaultColorFilters.Grayscale.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
            break;

        case 3:
            // Text Watermark
            TextWatermark watermark = new TextWatermark();
            watermark.Text             = DateTime.Now.ToString();
            watermark.ContentAlignment = ContentAlignment.TopRight;
            watermark.Font.Name        = "Arial";
            watermark.Font.Size        = 20;
            watermark.ForeColor        = Color.Yellow;
            watermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
            break;
        }

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

        // Display the generated image
        this.phOutputContainer.Visible = true;
    }
예제 #2
0
    protected void ProcessImage()
    {
        // Setup the source file name and the output file name
        string sourceImageFileName = this.imgSource.ImageUrl;
        string outputImageFileName = "~/repository/output/Ex_A_223.jpg";

        TextWatermark textWatermark = new TextWatermark();

        textWatermark.Text                = this.txtText.Text;
        textWatermark.ContentAlignment    = (ContentAlignment)Enum.Parse(typeof(ContentAlignment), this.ddlContentAlignment.SelectedValue);
        textWatermark.Unit                = (GfxUnit)Enum.Parse(typeof(GfxUnit), this.ddlMainUnit.SelectedValue);
        textWatermark.ContentDisplacement = new Point(int.Parse(this.ddlContentDisplacementX.SelectedValue, CultureInfo.InvariantCulture), int.Parse(this.ddlContentDisplacementY.SelectedValue, CultureInfo.InvariantCulture));
        textWatermark.ForeColor           = Color.FromArgb(int.Parse(this.ddlForeColorAlpha.SelectedValue, CultureInfo.InvariantCulture), ColorTranslator.FromHtml(this.txtForeColor.Text));
        textWatermark.Font.Name           = this.ddlFontName.SelectedValue;
        textWatermark.Font.Size           = float.Parse(this.ddlFontSize.SelectedValue, CultureInfo.InvariantCulture);
        textWatermark.Font.Bold           = this.cbFontBold.Checked;
        textWatermark.Font.Italic         = this.cbFontItalic.Checked;
        textWatermark.Font.Underline      = this.cbFontUnderline.Checked;
        textWatermark.Font.Strikeout      = this.cbFontStrikeout.Checked;
        textWatermark.TextRenderingHint   = (System.Drawing.Text.TextRenderingHint)Enum.Parse(typeof(System.Drawing.Text.TextRenderingHint), this.ddlTextRenderingHint.SelectedValue);
        textWatermark.TextContrast        = int.Parse(this.ddlTextContrast.SelectedValue, CultureInfo.InvariantCulture);

        using (StringFormat stringFormat = new StringFormat())
        {
            // Setup the string format parameters
            if (this.cbStringFormatFlags_DirectionVertical.Checked)
            {
                stringFormat.FormatFlags |= StringFormatFlags.DirectionVertical;
            }

            textWatermark.StringFormat = stringFormat;

            // Process the image
            textWatermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
        }

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

        // Display the generated image
        this.phOutputContainer.Visible = true;
    }
    protected void ProcessImage()
    {
        // Setup the source file name and the output file name
        string sourceImageFileName = this.imgSource.ImageUrl;
        string outputImageFileName = "~/repository/output/Ex_A_101.jpg";

        switch (this.ddlFilter.SelectedIndex)
        {
            case 0:
                // Fixed Size Crop Constraint
                int cropWidth = 160;
                int cropHeight = 350;
                new FixedCropConstraint(cropWidth, cropHeight).SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
                break;
            case 1:
                // Scaled Resize Constraint
                int maxWidth = 160;
                int maxHeight = 350;
                new ScaledResizeConstraint(maxWidth, maxHeight).SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
                break;
            case 2:
                // Grayscale Color Filter
                DefaultColorFilters.Grayscale.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
                break;
            case 3:
                // Text Watermark
                TextWatermark watermark = new TextWatermark();
                watermark.Text = DateTime.Now.ToString();
                watermark.ContentAlignment = ContentAlignment.TopRight;
                watermark.Font.Name = "Arial";
                watermark.Font.Size = 20;
                watermark.ForeColor = Color.Yellow;
                watermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
                break;
        }

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

        // Display the generated image
        this.phOutputContainer.Visible = true;
    }
    protected void ProcessImage()
    {
        // Setup the source file name and the output file name
        string sourceImageFileName = this.imgSource.ImageUrl;
        string outputImageFileName = "~/repository/output/Ex_A_223.jpg";

        TextWatermark textWatermark = new TextWatermark();
        textWatermark.Text = this.txtText.Text;
        textWatermark.ContentAlignment = (ContentAlignment)Enum.Parse(typeof(ContentAlignment), this.ddlContentAlignment.SelectedValue);
        textWatermark.Unit = (GfxUnit)Enum.Parse(typeof(GfxUnit), this.ddlMainUnit.SelectedValue);
        textWatermark.ContentDisplacement = new Point(int.Parse(this.ddlContentDisplacementX.SelectedValue, CultureInfo.InvariantCulture), int.Parse(this.ddlContentDisplacementY.SelectedValue, CultureInfo.InvariantCulture));
        textWatermark.ForeColor = Color.FromArgb(int.Parse(this.ddlForeColorAlpha.SelectedValue, CultureInfo.InvariantCulture), ColorTranslator.FromHtml(this.txtForeColor.Text));
        textWatermark.Font.Name = this.ddlFontName.SelectedValue;
        textWatermark.Font.Size = float.Parse(this.ddlFontSize.SelectedValue, CultureInfo.InvariantCulture);
        textWatermark.Font.Bold = this.cbFontBold.Checked;
        textWatermark.Font.Italic = this.cbFontItalic.Checked;
        textWatermark.Font.Underline = this.cbFontUnderline.Checked;
        textWatermark.Font.Strikeout = this.cbFontStrikeout.Checked;
        textWatermark.TextRenderingHint = (System.Drawing.Text.TextRenderingHint)Enum.Parse(typeof(System.Drawing.Text.TextRenderingHint), this.ddlTextRenderingHint.SelectedValue);
        textWatermark.TextContrast = int.Parse(this.ddlTextContrast.SelectedValue, CultureInfo.InvariantCulture);

        using (StringFormat stringFormat = new StringFormat())
        {
            // Setup the string format parameters
            if (this.cbStringFormatFlags_DirectionVertical.Checked)
            {
                stringFormat.FormatFlags |= StringFormatFlags.DirectionVertical;
            }

            textWatermark.StringFormat = stringFormat;

            // Process the image
            textWatermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
        }

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

        // Display the generated image
        this.phOutputContainer.Visible = true;
    }