Example #1
0
        public static void ApplyWaterMark(int x, int y, Bitmap bmp, string[] watermark)
        {
            if (watermark.Length == 0)
            {
                return;
            }
            try
            {
                int yOffset   = (int)(SystemFonts.DefaultFont.SizeInPoints * 1.5f);
                int maxLength = watermark.Max(s => s.Length);

                int xWidth = (int)Math.Round(maxLength * SystemFonts.DefaultFont.SizeInPoints * 0.7);
                int i      = 0;
                var pix    = bmp.GetPixel(x, y);


                using (var g = Graphics.FromImage(bmp))
                {
                    using (var textBrush = Brushes.Wheat) //new SolidBrush(textColor)
                    {
                        g.FillRectangle(Brushes.Black, 0, y, xWidth, y + yOffset * watermark.Length);
                        foreach (var s in watermark)
                        {
                            g.DrawString(s, SystemFonts.DefaultFont, textBrush, x, Math.Min(y + i * yOffset, 719));
                            i++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Error applying watermark : "));
                Trace.WriteLine(ex);
            }
        }