Beispiel #1
0
        public void AddWatermark(
            [Values(
                 FileAuthentication.None,
                 FileAuthentication.Password /*,
                                              * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file
                                              * FileAuthentication.CertificateFile,
                                              * FileAuthentication.CertificateStore*/)] FileAuthentication inputAuth,
            [Values(
                 WatermarkPosition.Above,
                 WatermarkPosition.Below)] WatermarkPosition position)
        {
            string inputFilePath     = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Watermark.pdf", this.inputDirectory);
            string watermarkFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Overlay.pdf", this.inputDirectory);
            string outputFilePath    = Path.Combine(this.outputDirectory, "Watermark.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <AddWatermarkProvider>();

            ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath);
            var watermarkPages = "4;1-2,2,2";

            ConfigureWatermarkFunctionValues(designer, FileAuthentication.None, watermarkFilePath, position, watermarkPages);
            designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath;

            var tester = new FunctionTester <AddWatermarkProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            PdfComparer.AssertText(outputFilePath, inputAuth, this.authenticationManager, "1\nWatermark\r\n2\nWatermark\r\n3\r\n4\nWatermark", null);
        }
Beispiel #2
0
        private static int GetTextAlign(SizeF textMetrics, int imageWidth, WatermarkPosition watermarkPosition)
        {
            int space;

            switch (watermarkPosition)
            {
            case WatermarkPosition.TopLeft:
            case WatermarkPosition.MiddleLeft:
            case WatermarkPosition.BottomLeft:
            default:
                space = 5;
                break;

            case WatermarkPosition.TopMiddle:
            case WatermarkPosition.Center:
            case WatermarkPosition.BottomMiddle:
                space = (int)(imageWidth - textMetrics.Width) / 2;
                break;

            case WatermarkPosition.TopRight:
            case WatermarkPosition.MiddleRight:
            case WatermarkPosition.BottomRight:
                space = (int)(imageWidth - textMetrics.Width) - 5;
                break;
            }

            return(space);
        }
Beispiel #3
0
        /// <summary>
        /// 对某张图片打水印。注意:如果图片的宽度或高度小于水印图片的宽度或高度,将不会被打水印
        /// </summary>
        /// <param name="imageFile">需要打水印的图片文件地址,可以为绝对或相对地址(相对于站点地址)</param>
        /// <param name="transparence">透明度,值范围0-1(小数),0:全透明; 1:不透明</param>
        /// <param name="position">水印图片的位置</param>
        public void AddWatermarkImage(string imageFile, float transparence, WatermarkPosition position)
        {
            string watermarkImage = this.WatermarkImage;

            if (string.IsNullOrEmpty(watermarkImage))
            {
                return;
            }

            watermarkImage = this.ToAbsoluteAppPath(watermarkImage);
            if (!File.Exists(watermarkImage))
            {
                return;
            }

            if (!File.Exists(imageFile))
            {
                return;
            }

            try
            {
                using (Stream stream = new MemoryStream(File.ReadAllBytes(imageFile)))
                {
                    using (Bitmap bitmap = (Bitmap)Bitmap.FromStream(stream))
                    {
                        if (bitmap.Watermark(watermarkImage, transparence, position))
                        {
                            bitmap.Save(imageFile);
                        }
                    }
                }
            }
            catch { }
        }
Beispiel #4
0
        /// <summary>
        /// 添加水印
        /// </summary>
        /// <param name="watermarkImage">水印图片</param>
        /// <param name="opacity">水印图片</param>
        /// <param name="watermarkPosition">水印位置</param>
        /// <param name="padding">水印边距</param>
        /// <returns></returns>
        public MemoryStream AddWatermark(Stream watermarkImage, float opacity = 1f, WatermarkPosition watermarkPosition = WatermarkPosition.BottomRight, int padding = 20)
        {
            using var img = Image.Load(_stream);
            var height = img.Height;
            var width  = img.Width;

            if (SkipWatermarkForSmallImages && (height < Math.Sqrt(SmallImagePixelsThreshold) || width < Math.Sqrt(SmallImagePixelsThreshold)))
            {
                return(_stream as MemoryStream ?? _stream.SaveAsMemoryStream());
            }

            var watermark = Image.Load(watermarkImage);

            watermark.Mutate(c => c.Resize(new ResizeOptions()
            {
                Size = new Size
                {
                    Width  = width / 10,
                    Height = height / 10,
                },
                Mode    = ResizeMode.Pad,
                Sampler = new BicubicResampler()
            }));
            int x, y;

            padding += (width - 1000) / 100;
            switch (watermarkPosition)
            {
            case WatermarkPosition.TopRight:
                x = width - watermark.Width - padding;
                y = padding;
                break;

            case WatermarkPosition.BottomLeft:
                x = padding;
                y = height - watermark.Height - padding;
                break;

            case WatermarkPosition.BottomRight:
                x = width - watermark.Width - padding;
                y = height - watermark.Height - padding;
                break;

            default:
                x = padding;
                y = padding;
                break;
            }

            img.Mutate(c =>
            {
                c.DrawImage(watermark, new Point(x, y), opacity);
                watermark.Dispose();
            });
            var ms = new MemoryStream();

            img.SaveAsWebp(ms);
            ms.Position = 0;
            return(ms);
        }
Beispiel #5
0
        public void DrawWatermark(Image original, Bitmap watermark, WatermarkPosition position, Color transparentColor, float opacity)
        {
            if (original == null)
                throw new ArgumentNullException("original");
            if (watermark == null)
                throw new ArgumentNullException("watermark");
            if (opacity < 0 || opacity > 1)
                throw new ArgumentOutOfRangeException("Watermark opacity value is out of range");

            Rectangle dest = new Rectangle(GetDestination(original.Size, watermark.Size, position), watermark.Size);

            using (Graphics g = Graphics.FromImage(original))
            {
                ImageAttributes attr = new ImageAttributes();
                ColorMatrix matrix = new ColorMatrix(new float[][] {
            new float[] { opacity, 0f, 0f, 0f, 0f },
            new float[] { 0f, opacity, 0f, 0f, 0f },
            new float[] { 0f, 0f, opacity, 0f, 0f },
            new float[] { 0f, 0f, 0f, opacity, 0f },
            new float[] { 0f, 0f, 0f, 0f, opacity } });
                attr.SetColorMatrix(matrix);
                //watermark.MakeTransparent(transparentColor);
                g.DrawImage(watermark, dest, 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel, attr, null, IntPtr.Zero);
                g.Save();
            }
        }
        /// <summary>
        /// 获取: 枚举 Uinatlex.ToolBox.ImageManager.WatermarkPosition 对应的 System.Drawing.Rectangle 对象
        /// </summary>
        /// <param name="positon">枚举 Uinatlex.ToolBox.ImageManager.WatermarkPosition: Uinatlex.ToolBox.ImageManager.WatermarkPosition</param>
        /// <param name="X">原图宽度: int</param>
        /// <param name="Y">原图高度: int</param>
        /// <param name="x">水印宽度: int</param>
        /// <param name="y">水印高度: int</param>
        /// <param name="i">边距: int</param>
        /// <returns>返回: 枚举 Uinatlex.ToolBox.ImageManager.WatermarkPosition 对应的 System.Drawing.Rectangle 对象: System.Drawing.Rectangle</returns>
        private Rectangle GetWatermarkRectangle(WatermarkPosition positon, int X, int Y, int x, int y, int i)
        {
            switch (positon)
            {
            case WatermarkPosition.LeftTop:
                return(new Rectangle(i, i, x, y));

            case WatermarkPosition.Left:
                return(new Rectangle(i, (Y - y) / 2, x, y));

            case WatermarkPosition.LeftBottom:
                return(new Rectangle(i, Y - y - i, x, y));

            case WatermarkPosition.Top:
                return(new Rectangle((X - x) / 2, i, x, y));

            case WatermarkPosition.Center:
                return(new Rectangle((X - x) / 2, (Y - y) / 2, x, y));

            case WatermarkPosition.Bottom:
                return(new Rectangle((X - x) / 2, Y - y - i, x, y));

            case WatermarkPosition.RightTop:
                return(new Rectangle(X - x - i, i, x, y));

            case WatermarkPosition.RightCenter:
                return(new Rectangle(X - x - i, (Y - y) / 2, x, y));

            default:
                return(new Rectangle(X - x - i, Y - y - i, x, y));
            }
        }
Beispiel #7
0
        /// <summary>
        /// 添加水印
        /// </summary>
        /// <param name="watermarkText">水印文字</param>
        /// <param name="color">水印颜色</param>
        /// <param name="watermarkPosition">水印位置</param>
        /// <param name="textPadding">边距</param>
        /// <param name="fontSize">字体大小</param>
        /// <param name="font">字体</param>
        /// <param name="textAntiAlias">不提示的情况下使用抗锯齿标志符号位图来绘制每个字符。
        ///    由于抗锯齿质量就越好。
        ///    因为关闭了提示,词干宽度之间的差异可能非常明显。</param>
        /// <returns></returns>
        public MemoryStream AddWatermark(string watermarkText, Color color, WatermarkPosition watermarkPosition = WatermarkPosition.BottomRight, int textPadding = 10, int fontSize = 20, Font font = null, bool textAntiAlias = true)
        {
            using var img = Image.FromStream(_stream);
            if (SkipWatermarkForSmallImages && img.Height * img.Width < SmallImagePixelsThreshold)
            {
                return(_stream.SaveAsMemoryStream());
            }

            using var graphic = Graphics.FromImage(img);
            if (textAntiAlias)
            {
                graphic.TextRenderingHint = TextRenderingHint.AntiAlias;
            }

            using var brush = new SolidBrush(color);
            if (img.Width / fontSize > 50)
            {
                fontSize = img.Width / 50;
            }

            using var f = font ?? new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold, GraphicsUnit.Pixel);
            var textSize = graphic.MeasureString(watermarkText, f);
            int x, y;

            textPadding += (img.Width - 1000) / 100;
            switch (watermarkPosition)
            {
            case WatermarkPosition.TopLeft:
                x = textPadding;
                y = textPadding;
                break;

            case WatermarkPosition.TopRight:
                x = img.Width - (int)textSize.Width - textPadding;
                y = textPadding;
                break;

            case WatermarkPosition.BottomLeft:
                x = textPadding;
                y = img.Height - (int)textSize.Height - textPadding;
                break;

            case WatermarkPosition.BottomRight:
                x = img.Width - (int)textSize.Width - textPadding;
                y = img.Height - (int)textSize.Height - textPadding;
                break;

            default:
                x = textPadding;
                y = textPadding;
                break;
            }

            graphic.DrawString(watermarkText, f, brush, new Point(x, y));
            var ms = new MemoryStream();

            img.Save(ms, img.RawFormat);
            ms.Position = 0;
            return(ms);
        }
Beispiel #8
0
        public static void AddWatermark(Bitmap bitmap, Bitmap watermark, WatermarkPosition position)
        {
            switch (position)
            {
            case WatermarkPosition.TopLeft:
                AddWatermark(bitmap, watermark, 5, 5);
                break;

            case WatermarkPosition.TopRight:
                AddWatermark(bitmap, watermark, bitmap.Width - watermark.Width - 5, 5);
                break;

            case WatermarkPosition.Center:
                AddWatermark(bitmap, watermark, bitmap.Width / 2 - watermark.Width / 2, bitmap.Height / 2 - watermark.Height / 2);
                break;

            case WatermarkPosition.BottomLeft:
                AddWatermark(bitmap, watermark, 5, bitmap.Height - watermark.Height - 5);
                break;

            case WatermarkPosition.BottomRight:
                AddWatermark(bitmap, watermark, bitmap.Width - watermark.Width - 5, bitmap.Height - watermark.Height - 5);
                break;
            }
        }
 /// <summary>
 /// 保存: 绘制水印的对象到图片文件 两张水印
 /// </summary>
 /// <param name="sBitmap">原图 System.Drawing.Bitmap 对象: System.Drawing.Bitmap</param>
 /// <param name="wBitmap">水印 System.Drawing.Bitmap 对象: System.Drawing.Bitmap</param>
 /// <param name="position">枚举 Uinatlex.ToolBox.ImageManager.WatermarkPosition : Uinatlex.ToolBox.ImageManager.WatermarkPosition</param>
 /// <param name="margin">水印边距: int</param>
 /// <param name="writepath">保存路径(包含完整路径,文件名及其扩展名): string</param>
 public void SaveWatermark(Bitmap sBitmap, Bitmap wBitmap, WatermarkPosition position, int lmargin, int rmargin, Bitmap wBitmap2, WatermarkPosition position2, int lmargin2, int rmargin2, string writepath, string nickname)
 {
     if (sBitmap.Width > wBitmap.Width && sBitmap.Height > wBitmap.Height)  //原图的大小需要打印水印的大小
     {
         Save(CreateWatermark2(sBitmap, wBitmap, position, lmargin, rmargin, wBitmap2, position2, lmargin2, rmargin2, nickname), writepath);
     }
 }
Beispiel #10
0
        public void AppliesTextBanner(string text, double scale, WatermarkPosition position)
        {
            var config = GetConfiguration();

            config.IntermediateOutputPath += GetOutputDirectorySuffix((nameof(text), text), (nameof(scale), scale), (nameof(position), position));
            var generator = new ImageResizeGenerator(config);

            var image = new OutputImage
            {
                Height     = 0,
                Width      = 0,
                InputFile  = Path.Combine(TestConstants.ImageDirectory, "dotnetbot.png"),
                OutputFile = Path.Combine(config.IntermediateOutputPath, "dotnetbot.png"),
                OutputLink = Path.Combine("Resources", "drawable-xxxhdpi", "dotnetbot.png"),
                RequiresBackgroundColor = true,
                Scale           = scale,
                ShouldBeVisible = true,
                Watermark       = new WatermarkConfiguration
                {
                    Text     = text,
                    Position = position
                }
            };

            generator.ProcessImage(image);

            VerifyImageContents(image);
        }
 /// <summary>
 /// 保存: 绘制水印的对象到图片文件
 /// </summary>
 /// <param name="sBitmap">原图 System.Drawing.Bitmap 对象: System.Drawing.Bitmap</param>
 /// <param name="wBitmap">水印 System.Drawing.Bitmap 对象: System.Drawing.Bitmap</param>
 /// <param name="position">枚举 Uinatlex.ToolBox.ImageManager.WatermarkPosition : Uinatlex.ToolBox.ImageManager.WatermarkPosition</param>
 /// <param name="margin">水印边距: int</param>
 /// <param name="writepath">保存路径(包含完整路径,文件名及其扩展名): string</param>
 public void SaveWatermark(Bitmap sBitmap, Bitmap wBitmap, WatermarkPosition position, int margin, string writepath)
 {
     if (sBitmap.Width > wBitmap.Width && sBitmap.Height > wBitmap.Height)  //原图的大小需要打印水印的大小
     {
         Save(CreateWatermark(sBitmap, wBitmap, position, margin), writepath);
     }
 }
    /// <summary>
    /// 生成: 原图绘制水印的 System.Drawing.Bitmap 对象  添加两张水印
    /// </summary>
    /// <param name="sBitmap">原图 System.Drawing.Bitmap 对象: System.Drawing.Bitmap</param>
    /// <param name="wBitmap">水印 System.Drawing.Bitmap 对象: System.Drawing.Bitmap</param>
    /// <param name="position">枚举 Uinatlex.ToolBox.ImageManager.WatermarkPosition : Uinatlex.ToolBox.ImageManager.WatermarkPosition</param>
    /// <param name="margin">水印边距: int</param>
    /// <returns>返回: 原图绘制水印的 System.Drawing.Bitmap 对象 System.Drawing.Bitmap</returns>
    public Bitmap CreateWatermark2(Bitmap sBitmap, Bitmap wBitmap, WatermarkPosition position, int lmargin, int rmargin, Bitmap wBitmap2, WatermarkPosition position2, int lmargin2, int rmargin2, string nickname)
    {
        Graphics graphics = Graphics.FromImage(sBitmap);

        graphics.DrawImage(wBitmap, GetWatermarkRectangle2(position, sBitmap.Width, sBitmap.Height, wBitmap.Width, wBitmap.Height, lmargin, rmargin));
        graphics.DrawImage(wBitmap2, GetWatermarkRectangle2(position2, sBitmap.Width, sBitmap.Height, wBitmap2.Width, wBitmap2.Height, lmargin2, rmargin2));

        if (!string.IsNullOrEmpty(nickname))
        {
            //添加文字
            float fontSize  = 42.0f; //字体大小
            float textWidth = 100;   //文本的长度
            //下面定义一个矩形区域,以后在这个矩形里画上白底黑字
            float rectX      = 340;  //260
            float rectY      = 80;
            float rectWidth  = 900;
            float rectHeight = fontSize + 8;
            //声明矩形域
            RectangleF textArea = new RectangleF(rectX, rectY, rectWidth, rectHeight);

            Font  font       = new Font("宋体", fontSize);                   //定义字体
            Brush whiteBrush = new SolidBrush(Color.FromArgb(3, 138, 82)); //白笔刷,画文字用#038A52
            Brush blackBrush = new SolidBrush(Color.Empty);                //黑笔刷,画背景用

            graphics.FillRectangle(blackBrush, rectX, rectY, rectWidth, rectHeight);

            graphics.DrawString(nickname, font, whiteBrush, textArea);
            //添加文字
        }
        graphics.Dispose();
        wBitmap.Dispose();
        return(sBitmap);
    }
    /// <summary>
    /// 获取: 枚举 Uinatlex.ToolBox.ImageManager.WatermarkPosition 对应的 System.Drawing.Rectangle 对象 左右边距分开设置
    /// </summary>
    /// <param name="positon">枚举 Uinatlex.ToolBox.ImageManager.WatermarkPosition: Uinatlex.ToolBox.ImageManager.WatermarkPosition</param>
    /// <param name="X">原图宽度: int</param>
    /// <param name="Y">原图高度: int</param>
    /// <param name="x">水印宽度: int</param>
    /// <param name="y">水印高度: int</param>
    /// <param name="i">边距: int</param>
    /// <returns>返回: 枚举 Uinatlex.ToolBox.ImageManager.WatermarkPosition 对应的 System.Drawing.Rectangle 对象: System.Drawing.Rectangle</returns>
    private Rectangle GetWatermarkRectangle2(WatermarkPosition positon, int X, int Y, int x, int y, int left, int right)
    {
        switch (positon)
        {
        case WatermarkPosition.LeftTop:
            return(new Rectangle(left, right, x, y));

        case WatermarkPosition.Left:
            return(new Rectangle(left, (Y - y) / 2, x, y));

        case WatermarkPosition.LeftBottom:
            return(new Rectangle(left, Y - y - right, x, y));

        case WatermarkPosition.Top:
            return(new Rectangle((X - x) / 2, right, x, y));

        case WatermarkPosition.Center:
            return(new Rectangle((X - x) / 2, (Y - y) / 2, x, y));

        case WatermarkPosition.Bottom:
            return(new Rectangle((X - x) / 2, Y - y - right, x, y));

        case WatermarkPosition.RightTop:
            return(new Rectangle(X - x - left, right, x, y));

        case WatermarkPosition.RightCenter:
            return(new Rectangle(X - x - left, (Y - y) / 2, x, y));

        default:
            return(new Rectangle(X - x - left, Y - y - right, x, y));
        }
    }
Beispiel #14
0
        /// <summary>
        /// 生成: 原图绘制水印的 System.Drawing.Bitmap 对象
        /// </summary>
        /// <param name="sBitmap">原图 System.Drawing.Bitmap 对象: System.Drawing.Bitmap</param>
        /// <param name="wBitmap">水印 System.Drawing.Bitmap 对象: System.Drawing.Bitmap</param>
        /// <param name="position">枚举 ImageManager.WatermarkPosition : ImageManager.WatermarkPosition</param>
        /// <param name="margin">水印边距: int</param>
        /// <returns>返回: 原图绘制水印的 System.Drawing.Bitmap 对象 System.Drawing.Bitmap</returns>
        /// <param name="quanju">全局打水印,true:是 false:否</param>
        private Bitmap CreateWatermark(Bitmap sBitmap, Bitmap wBitmap, WatermarkPosition position, int margin, bool global = default)
        {
            Graphics graphics = Graphics.FromImage(sBitmap);

            if (global)
            {
                int       w = (int)Math.Ceiling(((double)sBitmap.Width) / ((double)wBitmap.Width));
                int       h = (int)Math.Ceiling(((double)sBitmap.Height) / ((double)wBitmap.Height));
                int       x = 0;
                int       y = 0;
                Rectangle r;
                for (int i = 0; i < h; i++)
                {
                    for (int j = 0; j < w; j++)
                    {
                        x = j * wBitmap.Width + 1;
                        y = i * wBitmap.Height + 1;
                        r = new Rectangle(x, y, wBitmap.Width, wBitmap.Height);
                        graphics.DrawImage(wBitmap, r);
                    }
                }
            }
            else
            {
                graphics.DrawImage(wBitmap, GetWatermarkRectangle(position, sBitmap.Width, sBitmap.Height, wBitmap.Width, wBitmap.Height, margin));
            }
            graphics.Dispose();
            wBitmap.Dispose();
            return(sBitmap);
        }
Beispiel #15
0
 private static Point GetDestination(Size originalSize, Size watermarkSize, WatermarkPosition position)
 {
     Point destination = new Point(0, 0);
     switch (position)
     {
         case WatermarkPosition.TopRight:
             destination.X = originalSize.Width - watermarkSize.Width;
             break;
         case WatermarkPosition.BottomLeft:
             destination.Y = originalSize.Height - watermarkSize.Height;
             break;
         case WatermarkPosition.BottomRight:
             destination.X = originalSize.Width - watermarkSize.Width;
             destination.Y = originalSize.Height - watermarkSize.Height;
             break;
         case WatermarkPosition.Middle:
             destination.X = (originalSize.Width - watermarkSize.Width) / 2;
             destination.Y = (originalSize.Height - watermarkSize.Height) / 2;
             break;
         case WatermarkPosition.BottomMiddle:
             destination.X = (originalSize.Width - watermarkSize.Width) / 2;
             destination.Y = originalSize.Height - watermarkSize.Height;
             break;
     }
     return destination;
 }
Beispiel #16
0
        /// <summary>
        /// 获取水印的位置
        /// </summary>
        /// <returns></returns>
        private static Point GetWatermarkPosition(Image image, Image watermarkImage, WatermarkPosition position)
        {
            switch (position)
            {
            case WatermarkPosition.LeftTop:
                return(new Point(0, 0));

            case WatermarkPosition.TopMiddle:
                return(new Point((image.Width - watermarkImage.Width) / 2, 0));

            case WatermarkPosition.RightTop:
                return(new Point((image.Width - watermarkImage.Width), 0));

            case WatermarkPosition.LeftCenter:
                return(new Point(0, (image.Height - watermarkImage.Height) / 2));

            case WatermarkPosition.Center:
                return(new Point((image.Width - watermarkImage.Width) / 2, (image.Height - watermarkImage.Height) / 2));

            case WatermarkPosition.RightCenter:
                return(new Point((image.Width - watermarkImage.Width), (image.Height - watermarkImage.Height) / 2));

            case WatermarkPosition.LeftBottom:
                return(new Point(0, (image.Height - watermarkImage.Height)));

            case WatermarkPosition.MiddleBottom:
                return(new Point((image.Width - watermarkImage.Width) / 2, (image.Height - watermarkImage.Height)));

            default:
                return(new Point((image.Width - watermarkImage.Width), (image.Height - watermarkImage.Height)));
            }
        }
Beispiel #17
0
        private static Point GetDestination(Size originalSize, Size watermarkSize, WatermarkPosition position)
        {
            Point destination = new Point(0, 0);

            switch (position)
            {
            case WatermarkPosition.TopRight:
                destination.X = originalSize.Width - watermarkSize.Width;
                break;

            case WatermarkPosition.BottomLeft:
                destination.Y = originalSize.Height - watermarkSize.Height;
                break;

            case WatermarkPosition.BottomRight:
                destination.X = originalSize.Width - watermarkSize.Width;
                destination.Y = originalSize.Height - watermarkSize.Height;
                break;

            case WatermarkPosition.Middle:
                destination.X = (originalSize.Width - watermarkSize.Width) / 2;
                destination.Y = (originalSize.Height - watermarkSize.Height) / 2;
                break;
            }
            return(destination);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var file   = GetValueFromQueryString("file");
            int page   = Convert.ToInt32(GetValueFromQueryString("page"));
            int?width  = Convert.ToInt32(GetValueFromQueryString("width"));
            int?height = Convert.ToInt32(GetValueFromQueryString("width"));

            if (Utils.IsValidUrl(file))
            {
                file = Utils.DownloadToStorage(file);
            }

            string            watermarkText     = GetValueFromQueryString("watermarkText");
            int?              watermarkColor    = Convert.ToInt32(GetValueFromQueryString("watermarkColor"));
            WatermarkPosition watermarkPosition = (WatermarkPosition)Enum.Parse(typeof(WatermarkPosition), GetValueFromQueryString("watermarkPosition"), true);
            string            widthFromQuery    = GetValueFromQueryString("watermarkWidth");
            int?              watermarkWidth    = GetValueFromQueryString("watermarkWidth") == "null" ? null : (int?)Convert.ToInt32(GetValueFromQueryString("watermarkWidth"));
            byte              watermarkOpacity  = Convert.ToByte(GetValueFromQueryString("watermarkOpacity"));

            ViewerImageHandler handler             = Utils.CreateViewerImageHandler();
            ImageOptions       o                   = new ImageOptions();
            List <int>         pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;
            if (width.HasValue)
            {
                o.Width = Convert.ToInt32(width);
            }
            if (height.HasValue)
            {
                o.Height = Convert.ToInt32(height);
            }
            if (watermarkText != "")
            {
                o.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity);
            }
            Stream           stream = null;
            List <PageImage> list   = Utils.LoadPageImageList(handler, file, o);

            foreach (PageImage pageImage in list.Where(x => x.PageNumber == page))
            {
                stream = pageImage.Stream;
            }
            ;
            var result = new HttpResponseMessage(HttpStatusCode.OK);

            System.Drawing.Image image        = System.Drawing.Image.FromStream(stream);
            MemoryStream         memoryStream = new MemoryStream();

            image.Save(memoryStream, ImageFormat.Jpeg);

            HttpContext.Current.Response.ContentType = "image/jpeg";
            memoryStream.WriteTo(HttpContext.Current.Response.OutputStream);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }
 public string GetPrintableHtmlForImageBasedEngine(string path,
                                IImageUrlCreator urlCreator,
                                string displayName = null, string watermarkText = null, int? watermarkColor = null,
                                WatermarkPosition watermarkPosition = WatermarkPosition.Diagonal,
                                float watermarkFontSize = 0)
 {
     return GetPrintableHtml(path, false, urlCreator, null, null, displayName, watermarkText, watermarkColor, watermarkPosition, watermarkFontSize);
 }
Beispiel #20
0
 public string GetPrintableHtmlForImageBasedEngine(string path,
                                                   IImageUrlCreator urlCreator,
                                                   string displayName = null, string watermarkText = null, int?watermarkColor = null,
                                                   WatermarkPosition watermarkPosition = WatermarkPosition.Diagonal,
                                                   float watermarkFontSize             = 0)
 {
     return(GetPrintableHtml(path, false, urlCreator, null, null, displayName, watermarkText, watermarkColor, watermarkPosition, watermarkFontSize));
 }
        /// <summary>
        ///  加水印文字
        /// </summary>
        /// <param name="picture">imge 对象</param>
        /// <param name="_watermarkText">水印文字内容</param>
        /// <param name="_watermarkPosition">水印位置</param>
        /// <param name="_width">被加水印图片的宽</param>
        /// <param name="_height">被加水印图片的高</param>
        private void addWatermarkText(Graphics picture, string _watermarkText, WatermarkPosition _watermarkPosition, int _width, int _height)
        {
            int[] sizes = new int[] { 16, 14, 12, 10, 8, 6, 4 };
            //Font crFont = null;
            SizeF crSize = new SizeF();

            for (int i = 0; i < 7; i++)
            {
                //crFont = new Font("arial", 10, FontStyle.Regular);
                crSize = picture.MeasureString(_watermarkText, this.fontStyle);

                if ((ushort)crSize.Width < (ushort)_width)
                {
                    break;
                }
            }

            float xpos = 0;
            float ypos = 0;

            switch (_watermarkPosition)
            {
            case WatermarkPosition.WM_TOP_LEFT:
                xpos = ((float)_width * (float).01) + (crSize.Width / 2);
                ypos = (float)_height * (float).01;
                break;

            case WatermarkPosition.WM_TOP_RIGHT:
                xpos = ((float)_width * (float).99) - (crSize.Width / 2);
                ypos = (float)_height * (float).01;
                break;

            case WatermarkPosition.WM_BOTTOM_RIGHT:
                xpos = ((float)_width * this._waterWidth) - (crSize.Width / 2);
                ypos = ((float)_height * this._waterHeight) - crSize.Height;
                break;

            case WatermarkPosition.WM_BOTTOM_LEFT:
                xpos = ((float)_width * (float).01) + (crSize.Width / 2);
                ypos = ((float)_height * (float).99) - crSize.Height;
                break;
            }
            StringFormat StrFormat = new StringFormat();

            StrFormat.Alignment = StringAlignment.Center;

            SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(153, 0, 0, 0));

            picture.DrawString(_watermarkText, this.fontStyle, semiTransBrush2, xpos + 1, ypos + 1, StrFormat);

            SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(255, 255, 255));

            picture.DrawString(_watermarkText, this.fontStyle, semiTransBrush, xpos, ypos, StrFormat);

            semiTransBrush2.Dispose();
            semiTransBrush.Dispose();
        }
 public ImageWatermarkFilter(string imageFile, WatermarkPosition position, Point offset)
 {
     Name = "ImageWatermark";
     FilterType = FilterType.Video;
     ImageFile = imageFile;
     Position = position;
     Offset = offset;
     Rank = 0;
 }
 public ImageWatermarkFilter(string imageFile, WatermarkPosition position)
 {
     Name       = "ImageWatermark";
     FilterType = FilterType.Video;
     ImageFile  = imageFile;
     Position   = position;
     Offset     = new Point(10, 10);
     Rank       = 0;
 }
        private static string[] GetImageUrls(string applicationHost, string path, int startingPageNumber, int pageCount, int? pageWidth, int? quality, bool usePdf = true,
                                             string watermarkText = null, int? watermarkColor = null,
                                             WatermarkPosition? watermarkPosition = WatermarkPosition.Diagonal, float? watermarkWidth = 0,
                                             bool ignoreDocumentAbsence = false,
                                             bool useHtmlBasedEngine = false,
                                             bool supportPageRotation = false,
                                             string instanceId = null,
                                             string locale = null,
                                             int[] pageNumbers = null)
        {
            string[] pageUrls = new string[pageCount];

            RouteValueDictionary routeValueDictionary = new RouteValueDictionary
                {
                    {"path", path},
                    {"width", pageWidth},
                    {"quality", quality},
                    {"usePdf", usePdf},
                    {"useHtmlBasedEngine", useHtmlBasedEngine},
                    {"rotate", supportPageRotation}
                };

            if (!string.IsNullOrWhiteSpace(locale))
                routeValueDictionary.Add("locale", locale);

            if (!string.IsNullOrEmpty(watermarkText))
            {
                routeValueDictionary.Add("watermarkText", watermarkText);
                routeValueDictionary.Add("watermarkColor", watermarkColor);
                routeValueDictionary.Add("watermarkPosition", watermarkPosition);
                routeValueDictionary.Add("watermarkWidth", watermarkWidth);
            }

            if (!string.IsNullOrWhiteSpace(instanceId))
                routeValueDictionary.Add("instanceIdToken", instanceId);
            if (ignoreDocumentAbsence)
                routeValueDictionary.Add("ignoreDocumentAbsence", ignoreDocumentAbsence);

            if (pageNumbers != null)
            {
                for (int i = 0; i < pageCount; i++)
                {
                    routeValueDictionary["pageIndex"] = pageNumbers[i] - 1;
                    pageUrls[i] = ConvertUrlToAbsolute(applicationHost, CreateRelativeRequestUrl("GetDocumentPageImage", routeValueDictionary));
                }
            }
            else
            {
                for (int i = 0; i < pageCount; i++)
                {
                    routeValueDictionary["pageIndex"] = startingPageNumber + i;
                    pageUrls[i] = ConvertUrlToAbsolute(applicationHost, CreateRelativeRequestUrl("GetDocumentPageImage", routeValueDictionary));
                }
            }

            return pageUrls;
        }
 public ImageWatermarkFilter(string imageFile, WatermarkPosition position, Point offset)
 {
     Name       = "ImageWatermark";
     FilterType = FilterType.Video;
     ImageFile  = imageFile;
     Position   = position;
     Offset     = offset;
     Rank       = 0;
 }
Beispiel #26
0
        /// <summary>
        /// Set a watermark for this image.
        /// </summary>
        /// <param name="image">A image object.</param>
        /// <param name="watermark">The watermark will be seted.</param>
        /// <param name="position">The position of watermark.</param>
        /// <returns>A new image with the specified watermark.</returns>
        /// <exception cref="System.ArgumentNullException">watermark is null.</exception>
        public static Image Watermark(this Image image, Watermark watermark, WatermarkPosition position)
        {
            if (watermark == null)
            {
                throw new ArgumentNullException("watermark", "watermark is null.");
            }

            return(watermark.Mark(image, position));
        }
        /// <summary>
        /// 生成: 原图绘制水印的 System.Drawing.Bitmap 对象
        /// </summary>
        /// <param name="sBitmap">原图 System.Drawing.Bitmap 对象: System.Drawing.Bitmap</param>
        /// <param name="wBitmap">水印 System.Drawing.Bitmap 对象: System.Drawing.Bitmap</param>
        /// <param name="position">枚举 Uinatlex.ToolBox.ImageManager.WatermarkPosition : Uinatlex.ToolBox.ImageManager.WatermarkPosition</param>
        /// <param name="margin">水印边距: int</param>
        /// <returns>返回: 原图绘制水印的 System.Drawing.Bitmap 对象 System.Drawing.Bitmap</returns>
        public Bitmap CreateWatermark(Bitmap sBitmap, Bitmap wBitmap, WatermarkPosition position, int margin)
        {
            Graphics graphics = Graphics.FromImage(sBitmap);

            graphics.DrawImage(wBitmap, GetWatermarkRectangle(position, sBitmap.Width, sBitmap.Height, wBitmap.Width, wBitmap.Height, margin));
            graphics.Dispose();
            wBitmap.Dispose();
            return(sBitmap);
        }
 public ImageWatermarkFilter(string imageFile, WatermarkPosition position)
 {
     Name = "ImageWatermark";
     FilterType = FilterType.Video;
     ImageFile = imageFile;
     Position = position;
     Offset = new Point(10, 10);
     Rank = 0;
 }
Beispiel #29
0
 public Overlay(long start, long end, Size size, WatermarkPosition position, Point offset, OverlayType overlayType)
 {
     Id = Guid.NewGuid();
     StartTicks = start;
     EndTicks = end;
     Size = size;
     Position = position;
     Offset = offset;
     OverlayType = overlayType;
 }
Beispiel #30
0
 public byte[] GetPdfVersionCacheEnabled(string filePath, int countOfPagesToLeave,
                                         bool isPrintable,
                                         string watermarkText = null, int?watermarkColor = null,
                                         WatermarkPosition watermarkPosition = WatermarkPosition.Diagonal, float watermarkSizeInPercent = 0,
                                         bool ignoreDocumentAbsence          = false,
                                         bool useHtmlBasedEngine             = false,
                                         bool supportPageRotation            = false, bool supportPageReordering = false)
 {
     throw new NotImplementedException();
 }
 public byte[] GetWatermarkedImage(byte[] imageBytes, string watermarkText, bool fullWidth = true,
                                   int? watermarkColor = null,
                                   WatermarkPosition watermarkPosition = WatermarkPosition.Diagonal,
                                   float watermarkWidth = 0)
 {
     using (MemoryStream imageStream = new MemoryStream(imageBytes))
     {
         return GetWatermarkedImage(imageStream, watermarkText, fullWidth, watermarkColor, watermarkPosition, watermarkWidth);
     }
 }
Beispiel #32
0
        /// <summary>
        /// 生成水印并保存到文件
        /// </summary>
        /// <param name="imgPath">图片路径</param>
        /// <param name="waterPath">水印路径</param>
        /// <param name="pos">水印位置</param>
        /// <param name="handler">图片处理</param>
        /// <returns></returns>
        public static byte[] MakeWatermarkImage(string imgPath, string waterPath, WatermarkPosition pos,
                                                ImageGraphicsHandler handler)
        {
            Image img   = Image.FromFile(imgPath),
                  water = Image.FromFile(waterPath);

            byte[] bytes = MakeWatermarkImage(img, water, pos, handler);
            img.Dispose();
            return(bytes);
        }
 public Overlay(long start, long end, Size size, WatermarkPosition position, Point offset, OverlayType overlayType)
 {
     Id          = Guid.NewGuid();
     StartTicks  = start;
     EndTicks    = end;
     Size        = size;
     Position    = position;
     Offset      = offset;
     OverlayType = overlayType;
 }
 public byte[] GetWatermarkedImage(string imagePath, string watermarkText, bool fullWidth = true,
                                   int? watermarkColor = null,
                                   WatermarkPosition watermarkPosition = WatermarkPosition.Diagonal,
                                   float watermarkWidth = 0)
 {
     using (Stream imageStream = File.OpenRead(imagePath))
     {
         return GetWatermarkedImage(imageStream, watermarkText, fullWidth, watermarkColor, watermarkPosition, watermarkWidth);
     }
 }
 public byte[] GetWatermarkedImage(string imagePath, string watermarkText, bool fullWidth = true,
                                   int?watermarkColor = null,
                                   WatermarkPosition watermarkPosition = WatermarkPosition.Diagonal,
                                   float watermarkWidth = 0)
 {
     using (Stream imageStream = File.OpenRead(imagePath))
     {
         return(GetWatermarkedImage(imageStream, watermarkText, fullWidth, watermarkColor, watermarkPosition, watermarkWidth));
     }
 }
 public byte[] GetWatermarkedImage(byte[] imageBytes, string watermarkText, bool fullWidth = true,
                                   int?watermarkColor = null,
                                   WatermarkPosition watermarkPosition = WatermarkPosition.Diagonal,
                                   float watermarkWidth = 0)
 {
     using (MemoryStream imageStream = new MemoryStream(imageBytes))
     {
         return(GetWatermarkedImage(imageStream, watermarkText, fullWidth, watermarkColor, watermarkPosition, watermarkWidth));
     }
 }
        public void Page_Load(object sender, EventArgs e)
        {
            var file       = GetValueFromQueryString("file");
            var page       = Convert.ToInt32(GetValueFromQueryString("page"));
            var attachment = GetValueFromQueryString("attachment");

            string            watermarkText     = GetValueFromQueryString("watermarkText");
            int?              watermarkColor    = Convert.ToInt32(GetValueFromQueryString("watermarkColor"));
            WatermarkPosition watermarkPosition = (WatermarkPosition)Enum.Parse(typeof(WatermarkPosition), GetValueFromQueryString("watermarkPosition"), true);
            string            widthFromQuery    = GetValueFromQueryString("watermarkWidth");
            int?              watermarkWidth    = GetValueFromQueryString("watermarkWidth") == "null" ? null : (int?)Convert.ToInt32(GetValueFromQueryString("watermarkWidth"));
            byte              watermarkOpacity  = Convert.ToByte(GetValueFromQueryString("watermarkOpacity"));


            ViewerHtmlHandler handler             = Utils.CreateViewerHtmlHandler();
            List <int>        pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions o = new HtmlOptions();

            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;
            o.HtmlResourcePrefix  = (String.Format(
                                         "/page/resource?file=%s&page=%d&resource=",
                                         file,
                                         page
                                         ));
            if (watermarkText != "")
            {
                o.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity);
            }
            var docInfo = handler.GetDocumentInfo(file);

            List <PageHtml> list = Utils.LoadPageHtmlList(handler, file, o);

            string fullHtml = "";

            foreach (AttachmentBase attachmentBase in docInfo.Attachments.Where(x => x.Name == attachment))
            {
                // Get attachment document html representation
                List <PageHtml> pages = handler.GetPages(attachmentBase, o);
                foreach (PageHtml pageHtml in pages.Where(x => x.PageNumber == page))
                {
                    fullHtml += pageHtml.HtmlContent;
                }
                ;
            }

            HttpContext.Current.Response.ContentType = "text/html";
            HttpContext.Current.Response.Write(fullHtml);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }
Beispiel #38
0
        public string GetFileUrl(string path, bool getPdf, bool isPrintable, string fileDisplayName = null,
                                 string watermarkText = null, int?watermarkColor = null,
                                 WatermarkPosition watermarkPosition = WatermarkPosition.Diagonal, float watermarkWidth = 0,
                                 bool ignoreDocumentAbsence          = false,
                                 bool useHtmlBasedEngine             = false,
                                 bool supportPageRotation            = false,
                                 string instanceId = null)
        {
            NameValueCollection queryString = HttpUtility.ParseQueryString(string.Empty);

            queryString["path"] = path;
            if (!isPrintable)
            {
                queryString["getPdf"] = getPdf.ToString().ToLower();
                if (fileDisplayName != null)
                {
                    queryString["displayName"] = fileDisplayName;
                }
            }

            if (watermarkText != null)
            {
                queryString["watermarkText"]     = watermarkText;
                queryString["watermarkColor"]    = watermarkColor.ToString();
                queryString["watermarkPosition"] = watermarkPosition.ToString();
                queryString["watermarkWidth"]    = watermarkWidth.ToString(CultureInfo.InvariantCulture);
            }

            if (ignoreDocumentAbsence)
            {
                queryString["ignoreDocumentAbsence"] = ignoreDocumentAbsence.ToString().ToLower();
            }

            queryString["useHtmlBasedEngine"]  = useHtmlBasedEngine.ToString().ToLower();
            queryString["supportPageRotation"] = supportPageRotation.ToString().ToLower();
            if (!string.IsNullOrWhiteSpace(instanceId))
            {
                queryString[Constants.InstanceIdRequestKey] = instanceId;
            }
            string handlerName;

            if (isPrintable)
            {
                handlerName = "GetPdfWithPrintDialogHandler";
            }
            else
            {
                handlerName = "GetFileHandler";
            }

            string fileUrl = String.Format("{0}/{1}?{2}", EndpointPrefix, handlerName, queryString);

            return(fileUrl);
        }
Beispiel #39
0
 private string GetPrintableHtml(string path,
                                 bool useHtmlBasedEngine,
                                 IImageUrlCreator urlCreator,
                                 Func <string, int, int, string[]> pageHtmlCreator,
                                 string css,
                                 string displayName   = null,
                                 string watermarkText = null, int?watermarkColor = null,
                                 WatermarkPosition watermarkPosition = WatermarkPosition.Diagonal,
                                 float watermarkFontSize             = 0)
 {
     throw new NotImplementedException();
 }
        public string[] GetImageUrlsInternal(string path, int startingPageNumber, int pageCount, int? pageWidth,
                                     int? quality, bool usePdf = true,
                                     string watermarkText = null, int? watermarkColor = null,
                                     WatermarkPosition? watermarkPosition = WatermarkPosition.Diagonal, float? watermarkWidth = 0,
                                     bool ignoreDocumentAbsence = false,
                                     bool useHtmlBasedEngine = false,
                                     bool supportPageRotation = false,
                                     string instanceId = null, string locale = null)
        {
            NameValueCollection queryString = HttpUtility.ParseQueryString(string.Empty);
            queryString["path"] = path;
            queryString["width"] = pageWidth.ToString();
            queryString["quality"] = quality.ToString();
            queryString["usePdf"] = usePdf.ToString();
            if (!String.IsNullOrEmpty(watermarkText))
            {
                queryString["watermarkText"] = watermarkText;
                queryString["watermarkColor"] = watermarkColor.ToString();
                queryString["watermarkPosition"] = (watermarkPosition ?? WatermarkPosition.Diagonal).ToString();
                queryString["watermarkWidth"] = (watermarkWidth ?? 0).ToString(CultureInfo.InvariantCulture);
            }

            if (ignoreDocumentAbsence)
                queryString["ignoreDocumentAbsence"] = ignoreDocumentAbsence.ToString();
            queryString["useHtmlBasedEngine"] = useHtmlBasedEngine.ToString();
            queryString["rotate"] = supportPageRotation.ToString();

            if (!string.IsNullOrEmpty(Version))
            {
                queryString["v"] = Version;
            }
            if (!string.IsNullOrWhiteSpace(instanceId))
            {
                queryString[Constants.InstanceIdRequestKey] = instanceId;
            }

            if (!string.IsNullOrWhiteSpace(locale))
                queryString["locale"] = locale;

            var pageUrls = new string[pageCount];

            var handler = String.Format("GetDocumentPageImage{0}", UrlSuffix);

            for (int i = 0; i < pageCount; i++)
            {
                queryString["pageIndex"] = (startingPageNumber + i).ToString(CultureInfo.InvariantCulture);
                pageUrls[i] = String.Format("{0}/{1}?{2}", EndpointPrefix, handler, queryString);
            }

            return pageUrls;
        }
Beispiel #41
0
        /// <summary>
        /// ��ԭʼͼƬ�������ˮӡ֮��洢
        /// </summary>
        /// <param name="srcPath"></param>
        /// <param name="savePath"></param>
        /// <param name="words"></param>
        /// <param name="wp"></param>
        /// <param name="fontSize"></param>
        public static void MakeByText( String srcPath, String savePath, String words, WatermarkPosition wp, int fontSize )
        {
            using (Image src = Image.FromFile( srcPath )) {
                using (Bitmap bm = new Bitmap( srcPath )) {
                    using (Graphics g = Graphics.FromImage( bm )) {

                        FontAndSize fs = FontAndSize.GetValue( g, words, "arial", fontSize, src.Width );
                        PointF p = getTextPoint( src, fs.size, wp );
                        StringFormat sf = getStringFormat();

                        drawText( g, words, fs.font, p, sf );

                        try {
                            bm.Save( savePath );
                        }
                        catch (Exception e) {
                            throw e;
                        }

                    }
                }
            }
        }
Beispiel #42
0
        /// <summary>
        /// ��ԭʼͼƬ���ͼƬˮӡ֮��洢
        /// </summary>
        /// <param name="srcPath"></param>
        /// <param name="savePath"></param>
        /// <param name="watermarkPath"></param>
        /// <param name="wp"></param>
        public static void MakeByPic( String srcPath, String savePath, String watermarkPath, WatermarkPosition wp )
        {
            using (Image src = Image.FromFile( srcPath )) {
                using (Bitmap bm = new Bitmap( srcPath )) {
                    using (Graphics g = Graphics.FromImage( bm )) {
                        using (Image wm = Image.FromFile( watermarkPath )) {

                            ImageAttributes imgAttr = getImageAttributes();
                            Rectangle rect = getPicRectangle( src, wm, wp );

                            g.DrawImage( wm, rect, 0, 0, wm.Width, wm.Height, GraphicsUnit.Pixel, imgAttr );

                            try {
                                bm.Save( savePath );
                            }
                            catch (Exception e) {
                                throw e;
                            }

                        }
                    }
                }
            }
        }
        /// <summary>
        ///  加水印文字
        /// </summary>
        /// <param name="picture">imge 对象</param>
        /// <param name="_watermarkText">水印文字内容</param>
        /// <param name="_watermarkPosition">水印位置</param>
        /// <param name="_width">被加水印图片的宽</param>
        /// <param name="_height">被加水印图片的高</param>
        private void addWatermarkText(Graphics picture, string _watermarkText, WatermarkPosition _watermarkPosition, int _width, int _height)
        {
            int[] sizes = new int[] { 16, 14, 12, 10, 8, 6, 4 };
            //Font crFont = null;
            SizeF crSize = new SizeF();
            for (int i = 0; i < 7; i++)
            {
                //crFont = new Font("arial", 10, FontStyle.Regular);
                crSize = picture.MeasureString(_watermarkText, this.fontStyle);

                if ((ushort)crSize.Width < (ushort)_width)
                    break;
            }

            float xpos = 0;
            float ypos = 0;

            switch (_watermarkPosition)
            {
                case WatermarkPosition.WM_TOP_LEFT:
                    xpos = ((float)_width * (float).01) + (crSize.Width / 2);
                    ypos = (float)_height * (float).01;
                    break;
                case WatermarkPosition.WM_TOP_RIGHT:
                    xpos = ((float)_width * (float).99) - (crSize.Width / 2);
                    ypos = (float)_height * (float).01;
                    break;
                case WatermarkPosition.WM_BOTTOM_RIGHT:
                    xpos = ((float)_width * this._waterWidth) - (crSize.Width / 2);
                    ypos = ((float)_height * this._waterHeight) - crSize.Height;
                    break;
                case WatermarkPosition.WM_BOTTOM_LEFT:
                    xpos = ((float)_width * (float).01) + (crSize.Width / 2);
                    ypos = ((float)_height * (float).99) - crSize.Height;
                    break;
            }
            StringFormat StrFormat = new StringFormat();
            StrFormat.Alignment = StringAlignment.Center;

            SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(153, 0, 0, 0));
            picture.DrawString(_watermarkText, this.fontStyle, semiTransBrush2, xpos + 1, ypos + 1, StrFormat);

            SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(255, 255, 255));
            picture.DrawString(_watermarkText, this.fontStyle, semiTransBrush, xpos, ypos, StrFormat);

            semiTransBrush2.Dispose();
            semiTransBrush.Dispose();
        }
Beispiel #44
0
        private static Rectangle getPicRectangle( Image src, Image wm, WatermarkPosition wp )
        {
            int x = 10;
            int y = 10;

            if (wp == WatermarkPosition.TopLeft) {
            }
            else if (wp == WatermarkPosition.TopCenter) {
                x = src.Width / 2 - wm.Width / 2;
                y = 10;
            }
            else if (wp == WatermarkPosition.TopRight) {
                x = ((src.Width - wm.Width) - 10);
                y = 10;
            }
            else if (wp == WatermarkPosition.BottomLeft) {
                x = 10;
                y = src.Height - wm.Height - 10;
            }
            else if (wp == WatermarkPosition.BottomCenter) {
                x = src.Width / 2 - wm.Width / 2;
                y = src.Height - wm.Height - 10;
            }
            else if (wp == WatermarkPosition.BottomRight) {
                x = ((src.Width - wm.Width) - 10);
                y = src.Height - wm.Height - 10;
            }

            return new Rectangle( x, y, wm.Width, wm.Height );
        }
Beispiel #45
0
        private static PointF getTextPoint( Image src, SizeF textSize, WatermarkPosition wp )
        {
            float x = textSize.Width / 2 + 5;
            float y = textSize.Height / 2 + 5;

            int margin = 10;

            if (wp == WatermarkPosition.TopLeft) {
                x = getLeftPosition( src, textSize, margin );
                y = getTopPosition( src, textSize, margin );
            }
            else if (wp == WatermarkPosition.TopCenter) {
                x = src.Width / 2;
                y = getTopPosition( src, textSize, margin );
            }
            else if (wp == WatermarkPosition.TopRight) {
                x = getRightPosition( src, textSize, margin );
                y = getTopPosition( src, textSize, margin );
            }
            else if (wp == WatermarkPosition.BottomLeft) {
                x = getLeftPosition( src, textSize, margin );
                y = getBottomPosition( src, textSize, margin );
            }
            else if (wp == WatermarkPosition.BottomCenter) {
                x = src.Width / 2;
                y = getBottomPosition( src, textSize, margin );
            }
            else if (wp == WatermarkPosition.BottomRight) {
                x = getRightPosition( src, textSize, margin );
                y = getBottomPosition( src, textSize, margin );
            }

            return new PointF( x, y );
        }
Beispiel #46
0
        /// <summary>
        /// 生成水印并保存到文件
        /// </summary>
        /// <param name="imgPath">图片路径</param>
        /// <param name="waterPath">水印路径</param>
        /// <param name="pos">水印位置</param>
        /// <param name="handler">图片处理</param>
        /// <returns></returns>
        public static byte[] MakeWatermarkImage(string imgPath, string waterPath, WatermarkPosition pos,
            ImageGraphicsHandler handler)
        {
            Image img = Image.FromFile(imgPath),
                water = Image.FromFile(waterPath);

            byte[] bytes = MakeWatermarkImage(img, water, pos, handler);
            img.Dispose();
            return bytes;
        }
Beispiel #47
0
 /// <summary>
 /// 生成水印
 /// </summary>
 /// <param name="img">图片</param>
 /// <param name="water">水印</param>
 /// <param name="pos">预置的水印位置</param>
 /// <returns>图片内存流</returns>
 public static byte[] MakeWatermarkImage(Image img, Image water, WatermarkPosition pos)
 {
     return MakeWatermarkImage(img, water, pos, null);
 }
Beispiel #48
0
 /// <summary>
 /// 生成水印并保存到文件
 /// </summary>
 /// <param name="imgPath">图片路径</param>
 /// <param name="waterPath">水印路径</param>
 /// <param name="pos">水印位置</param>
 /// <returns></returns>
 public static byte[] MakeWatermarkImage(string imgPath, string waterPath, WatermarkPosition pos)
 {
     return MakeWatermarkImage(imgPath, waterPath, pos, null);
 }
 private string GetPrintableHtml(string path,
     bool useHtmlBasedEngine,
     IImageUrlCreator urlCreator,
     Func<string, int, int, string[]> pageHtmlCreator,
     string css,
     string displayName = null,
     string watermarkText = null, int? watermarkColor = null,
     WatermarkPosition watermarkPosition = WatermarkPosition.Diagonal,
     float watermarkFontSize = 0)
 {
     throw new NotImplementedException();
 }
 public string GetFileUrl(string path, bool getPdf, bool isPrintable, string fileDisplayName = null,
                          string watermarkText = null, int? watermarkColor = null,
                          WatermarkPosition? watermarkPosition = WatermarkPosition.Diagonal, float? watermarkWidth = 0,
                          bool ignoreDocumentAbsence = false,
                          bool useHtmlBasedEngine = false,
                          bool supportPageRotation = false,
                          string instanceId = null)
 {
     UrlHelper urlHelper = new UrlHelper(ControllerContext.RequestContext);
     string displayNameEncoded = Server.UrlEncode(fileDisplayName);
     string instanceIdToken = instanceId;
     string fileUrl = ConvertUrlToAbsolute(urlHelper.Action(isPrintable ? "GetPdfWithPrintDialog" : "GetFile",
                                           new
                                           {
                                               path,
                                               displayName = displayNameEncoded,
                                               getPdf,
                                               isPrintable,
                                               watermarkText,
                                               watermarkColor,
                                               watermarkPosition,
                                               watermarkWidth,
                                               ignoreDocumentAbsence,
                                               useHtmlBasedEngine,
                                               supportPageRotation,
                                               instanceIdToken
                                           }));
     return fileUrl;
 }
        public string[] GetImageUrlsInternal(string path, int startingPageNumber, int pageCount, int? pageWidth, int? quality, bool usePdf = true,
                                              string watermarkText = null, int? watermarkColor = null,
                                              WatermarkPosition? watermarkPosition = WatermarkPosition.Diagonal, float? watermarkWidth = 0,
                                              bool ignoreDocumentAbsence = false,
                                              bool useHtmlBasedEngine = false,
                                              bool supportPageRotation = false,
                                              string instanceId = null,
                                              string locale = null)
        {
            string[] pageUrls;
            UrlHelper url = new UrlHelper(ControllerContext.RequestContext);
            string applicationHost = _applicationPathFinder.GetApplicationHost();
            if (applicationHost.EndsWith("/"))
            {
                applicationHost = applicationHost.Substring(0, applicationHost.Length - 1);
            }

            pageUrls = new string[pageCount];
            if (_helper.GetStorageProvider() == SupportedStorageProvider.Local)
            {
                RouteValueDictionary routeValueDictionary = new RouteValueDictionary(){
                                                                    {"path", path},
                                                                    {"width", pageWidth},
                                                                    {"quality", quality},
                                                                    {"usePdf", usePdf},
                                                                       
                                                                    {"useHtmlBasedEngine", useHtmlBasedEngine},
                                                                    {"rotate", supportPageRotation}
                                                                };

                if (!string.IsNullOrEmpty(locale))
                    routeValueDictionary.Add("locale", locale);

                if (!string.IsNullOrEmpty(watermarkText))
                {
                    routeValueDictionary.Add("watermarkText", watermarkText);
                    routeValueDictionary.Add("watermarkColor", watermarkColor);
                    routeValueDictionary.Add("watermarkPosition", watermarkPosition);
                    routeValueDictionary.Add("watermarkWidth", watermarkWidth);
                }
                if (!string.IsNullOrWhiteSpace(instanceId))
                {
                    routeValueDictionary.Add(Constants.InstanceIdRequestKey, instanceId);
                }
                if (ignoreDocumentAbsence)
                    routeValueDictionary.Add("ignoreDocumentAbsence", ignoreDocumentAbsence);

                for (int i = 0; i < pageCount; i++)
                {
                    routeValueDictionary["pageIndex"] = startingPageNumber + i;
                    pageUrls[i] = string.Format("{0}{1}", applicationHost,
                                                url.Action("GetDocumentPageImage", routeValueDictionary));
                }
            }
            else
            {
                pageUrls = _coreHandler.GetPageImageUrlsOnThirdPartyStorage(path, pageCount, quality, pageWidth, null, true);
            }

            return pageUrls;
        }
Beispiel #52
0
        /// <summary>
        /// 生成水印
        /// </summary>
        /// <param name="img">图片</param>
        /// <param name="water">水印</param>
        /// <param name="pos">预置的水印位置</param>
        /// <param name="format">图像格式</param>
        /// <param name="handler">处理图片</param>
        /// <returns>图片内存流</returns>
        public static byte[] MakeWatermarkImage(
            Image img,
            Image water,
            WatermarkPosition pos,
            ImageGraphicsHandler handler)
        {
            int x;
            int y;

            int xOffset = 5; //宽度偏移量
            int yOffset = 5; //高度偏移量
            switch (pos)
            {
                case WatermarkPosition.Bottom:
                    //正下方
                    x = (img.Width - water.Width)/2;
                    y = img.Height - water.Height - yOffset;
                    break;
                case WatermarkPosition.LeftBottom:
                    //左下方
                    x = xOffset;
                    y = img.Height - water.Height - yOffset;
                    break;
                case WatermarkPosition.Right:
                    //右方
                    x = img.Width - water.Width - xOffset;
                    y = (img.Height - water.Height)/2;
                    break;
                case WatermarkPosition.Middle:
                    //正中
                    x = (img.Width - water.Width)/2;
                    y = (img.Height - water.Height)/2;
                    break;
                case WatermarkPosition.Left:
                    //左边
                    x = xOffset;
                    y = (img.Height - water.Height)/2;
                    break;
                case WatermarkPosition.RightTop:
                    //右上方
                    x = img.Width - water.Width - xOffset;
                    y = yOffset;
                    break;
                case WatermarkPosition.Top:
                    //正上方
                    x = (img.Width - water.Width)/2;
                    y = yOffset;
                    break;
                case WatermarkPosition.LeftTop:
                    //左上方
                    x = xOffset;
                    y = yOffset;
                    break;

                default:
                case WatermarkPosition.Default:
                case WatermarkPosition.RightBottom:
                    //右下角
                    x = img.Width - water.Width - xOffset;
                    y = img.Height - water.Height - yOffset;
                    break;
            }

            return MakeWatermarkImage(img, water, new Point(x, y), handler);
        }
Beispiel #53
0
        /// <summary>
        /// 生成水印并保存到文件
        /// </summary>
        /// <param name="img">图片</param>
        /// <param name="water">水印</param>
        /// <param name="pos">预置的水印位置</param>
        public static void SaveWatermarkImage(Image img, Image water, string savePath, WatermarkPosition pos)
        {
            MakeWatermarkImage(img, water, pos, thumb => { thumb.Save(savePath, img.RawFormat); });

            img.Dispose();
        }
Beispiel #54
0
 /// <summary>
 /// 生成水印并保存到文件
 /// </summary>
 /// <param name="imgPath">图片路径</param>
 /// <param name="waterPath">水印路径</param>
 /// <param name="savePath">保存路径</param>
 public static void SaveWatermarkImage(string imgPath, string waterPath, string savePath, WatermarkPosition pos)
 {
     MakeWatermarkImage(imgPath, waterPath, pos, img => { img.Save(savePath, img.RawFormat); });
 }
 public HandleImage()
 {
     this._oldPath = "/Images/quan.jpg";
     this._newPath = "/Images";
     this._wmtType = 1;
     this._waterMarkContent = "mcake";
     this._graphicsColor = Color.White;
     this._fontStyle = new Font("arial", 10, FontStyle.Regular);
     this._watermarkPosition = WatermarkPosition.WM_BOTTOM_RIGHT;
     this._waterHeight = .99f;
     this._waterWidth = .99f;
     this._newImageName = "mcake";
 }
        /// <summary>
        ///  加水印图片
        /// </summary>
        /// <param name="picture">imge 对象</param>
        /// <param name="WaterMarkPicPath">水印图片的地址</param>
        /// <param name="_watermarkPosition">水印位置</param>
        /// <param name="_width">被加水印图片的宽</param>
        /// <param name="_height">被加水印图片的高</param>
        private void addWatermarkImage(Graphics picture, string waterMarkPicPath, WatermarkPosition _watermarkPosition, int _width, int _height)
        {
            Image watermark = new Bitmap(waterMarkPicPath);

            ImageAttributes imageAttributes = new ImageAttributes();
            ColorMap colorMap = new ColorMap();

            colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
            ColorMap[] remapTable = { colorMap };

            imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

            float[][] colorMatrixElements = {
                                                new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
                                                new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
                                                new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
                                                new float[] {0.0f,  0.0f,  0.0f,  0.3f, 0.0f},
                                                new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
                                            };

            ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);

            imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            int xpos = 0;
            int ypos = 0;
            int WatermarkWidth = 0;
            int WatermarkHeight = 0;
            double bl = 1d;
            //计算水印图片的比率
            //取背景的1/4宽度来比较
            if ((_width > watermark.Width * 4) && (_height > watermark.Height * 4))
            {
                bl = 1;
            }
            else if ((_width > watermark.Width * 4) && (_height < watermark.Height * 4))
            {
                bl = Convert.ToDouble(_height / 4) / Convert.ToDouble(watermark.Height);

            }
            else

                if ((_width < watermark.Width * 4) && (_height > watermark.Height * 4))
                {
                    bl = Convert.ToDouble(_width / 4) / Convert.ToDouble(watermark.Width);
                }
                else
                {
                    if ((_width * watermark.Height) > (_height * watermark.Width))
                    {
                        bl = Convert.ToDouble(_height / 4) / Convert.ToDouble(watermark.Height);

                    }
                    else
                    {
                        bl = Convert.ToDouble(_width / 4) / Convert.ToDouble(watermark.Width);

                    }

                }

            WatermarkWidth = Convert.ToInt32(watermark.Width * bl);
            WatermarkHeight = Convert.ToInt32(watermark.Height * bl);

            switch (_watermarkPosition)
            {
                case WatermarkPosition.WM_TOP_LEFT:
                    xpos = 10;
                    ypos = 10;
                    break;
                case WatermarkPosition.WM_TOP_RIGHT:
                    xpos = _width - WatermarkWidth - 10;
                    ypos = 10;
                    break;
                case WatermarkPosition.WM_BOTTOM_RIGHT:
                    xpos = _width - WatermarkWidth - 10;
                    ypos = _height - WatermarkHeight - 10;
                    break;
                case WatermarkPosition.WM_BOTTOM_LEFT:
                    xpos = 10;
                    ypos = _height - WatermarkHeight - 10;
                    break;
            }

            picture.DrawImage(watermark, new Rectangle(xpos, ypos, WatermarkWidth, WatermarkHeight), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel, imageAttributes);

            watermark.Dispose();
            imageAttributes.Dispose();
        }
Beispiel #57
0
        public static bool UpdateWatermark(string code, string watermark, WatermarkPosition position, string timezone)
        {
            string query = @"UPDATE [dbo].[Timelapses] " +
                           "SET [WatermarkImage]=@WatermarkImage, [WatermarkPosition]=@WatermarkPosition, [ModifiedDT]=@ModifiedDT " +
                           "WHERE (Code = '" + code + "')";
            try
            {
                var p1 = new SqlParameter("@WatermarkImage", watermark);
                var p2 = new SqlParameter("@WatermarkPosition", (int)position);
                var p3 = new SqlParameter("@ModifiedDT", Utils.ConvertFromUtc(DateTime.UtcNow, timezone));

                var cmd = new SqlCommand { CommandText = query, CommandType = CommandType.Text };
                cmd.Parameters.Add(p1);
                cmd.Parameters.Add(p2);
                cmd.Parameters.Add(p3);
                Connection.OpenConnection();
                cmd.Connection = Connection.DbConnection;
                bool result = (cmd.ExecuteNonQuery() > 0);
                Connection.CloseConnection();
                cmd.Dispose();
                return result;
            }
            catch (Exception ex)
            {
                Utils.FileLog("TimelapseDao UpdateWatermark(string code, string watermark, WatermarkPosition position) " + ex.Message);
                return false;
            }
            finally
            { Connection.CloseConnection(); }
        }
Beispiel #58
0
        /// <summary>
        /// 添加文字水印
        /// </summary>
        /// <param name="originalImage">Image</param>
        /// <param name="text">水印字</param>
        /// <param name="position">水印位置</param>
        /// <param name="font">字体</param>
        /// <param name="brush">颜色</param>
        /// <returns></returns>
        public static Image WatermarkText(Image originalImage, string text, WatermarkPosition position, Font font, Brush brush)
        {
            using (Graphics g = Graphics.FromImage(originalImage))
            {
                Font tempfont = null;
                SizeF sizeF = new SizeF();
                sizeF = g.MeasureString(text, font);

                if (sizeF.Width >= originalImage.Width)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        tempfont = new Font(font.FontFamily, sizes[i], font.Style);

                        sizeF = g.MeasureString(text, tempfont);

                        if (sizeF.Width < originalImage.Width)
                            break;
                    }
                }
                else
                {
                    tempfont = font;
                }

                float x = (float)originalImage.Width * (float)0.01;
                float y = (float)originalImage.Height * (float)0.01;

                switch (position)
                {
                    case WatermarkPosition.TopLeft:
                        break;
                    case WatermarkPosition.TopRight:
                        x = (float)((float)originalImage.Width * (float)0.99 - sizeF.Width);
                        break;
                    case WatermarkPosition.BottomLeft:
                        y = (float)((float)originalImage.Height * (float)0.99 - sizeF.Height);
                        break;
                    case WatermarkPosition.BottomRight:
                        x = (float)((float)originalImage.Width * (float)0.99 - sizeF.Width);
                        y = (float)((float)originalImage.Height * (float)0.99 - sizeF.Height);
                        break;
                    case WatermarkPosition.Center:
                        x = (float)((float)originalImage.Width / 2 - sizeF.Width / 2);
                        y = (float)((float)originalImage.Height / 2 - sizeF.Height / 2);
                        break;
                    default:
                        break;
                }

                g.DrawString(text, tempfont, brush, x, y);

                return originalImage;
            }
        }
Beispiel #59
0
 /// <summary>
 /// 添加文字水印   默认字体:Verdana  12号大小  斜体  黑色
 /// </summary>
 /// <param name="originalImage">Image</param>
 /// <param name="text">水印字</param>
 /// <param name="position">水印位置</param>
 /// <returns></returns>
 public static Image WatermarkText(Image originalImage, string text, WatermarkPosition position)
 {
     return WatermarkText(originalImage, text, position, new Font("微软雅黑", 14, FontStyle.Italic), new SolidBrush(Color.White));
 }
Beispiel #60
0
        /// <summary>
        /// 添加图片水印
        /// </summary>
        /// <param name="originalImage">Image</param>
        /// <param name="watermarkImage">水印Image</param>
        /// <param name="position">位置</param>
        /// <returns></returns>
        public static Image WatermarkImage(Image originalImage, Image watermarkImage, WatermarkPosition position)
        {
            ImageAttributes imageAttributes = new ImageAttributes();
            ColorMap colorMap = new ColorMap();
            colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
            ColorMap[] remapTable = { colorMap };

            imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

            float[][] colorMatrixElements = {    new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
                                                 new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
                                                 new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
                                                 new float[] {0.0f,  0.0f,  0.0f,  0.3f, 0.0f},
                                                 new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
                                             };

            ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
            imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            int x = 0;
            int y = 0;
            int watermarkWidth = 0;
            int watermarkHeight = 0;
            double bl = 1d;

            if ((originalImage.Width > watermarkImage.Width * 4) && (originalImage.Height > watermarkImage.Height * 4))
            {
                bl = 1;
            }
            else if ((originalImage.Width > watermarkImage.Width * 4) && (originalImage.Height < watermarkImage.Height * 4))
            {
                bl = Convert.ToDouble(originalImage.Height / 4) / Convert.ToDouble(watermarkImage.Height);

            }
            else if ((originalImage.Width < watermarkImage.Width * 4) && (originalImage.Height > watermarkImage.Height * 4))
            {
                bl = Convert.ToDouble(originalImage.Width / 4) / Convert.ToDouble(watermarkImage.Width);
            }
            else
            {
                if ((originalImage.Width * watermarkImage.Height) > (originalImage.Height * watermarkImage.Width))
                {
                    bl = Convert.ToDouble(originalImage.Height / 4) / Convert.ToDouble(watermarkImage.Height);

                }
                else
                {
                    bl = Convert.ToDouble(originalImage.Width / 4) / Convert.ToDouble(watermarkImage.Width);
                }
            }

            watermarkWidth = Convert.ToInt32(watermarkImage.Width * bl);
            watermarkHeight = Convert.ToInt32(watermarkImage.Height * bl);

            switch (position)
            {
                case WatermarkPosition.TopLeft:
                    x = 10;
                    y = 10;
                    break;
                case WatermarkPosition.TopRight:
                    y = 10;
                    x = originalImage.Width - watermarkWidth - 10;
                    break;
                case WatermarkPosition.BottomLeft:
                    x = 10;
                    y = originalImage.Height - watermarkHeight - 10;
                    break;
                case WatermarkPosition.BottomRight:
                    x = originalImage.Width - watermarkWidth - 10;
                    y = originalImage.Height - watermarkHeight - 10;
                    break;
                case WatermarkPosition.Center:
                    x = originalImage.Width / 2 - watermarkWidth / 2;
                    y = originalImage.Height / 2 - watermarkHeight / 2;
                    break;
                default:
                    break;
            }
            using (Graphics g = Graphics.FromImage(originalImage))
            {
                g.DrawImage(watermarkImage, new Rectangle(x, y, watermarkWidth, watermarkHeight), 0, 0, watermarkImage.Width, watermarkImage.Height, GraphicsUnit.Pixel, imageAttributes);
            }

            return originalImage;
        }