PatPositron

WaterMark Class

Jun 8th, 2013
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. class WaterMark
  2. {
  3.     public WaterMark()
  4.     {
  5.         //-------MADE BY PATPOSITRON-------------
  6.         //-This watermark class was made by------
  7.         //-PatPositron on HF. Reuse as needed----
  8.         //-------PLEASE LEAVE CREDITS HERE-------
  9.     }
  10.     /// <summary>
  11.     /// WaterMark the image with a string.
  12.     /// </summary>
  13.     /// <param name="location">Location of desired image.</param>
  14.     /// <param name="mark">The string used to mark the image.</param>
  15.     /// <param name="x">The X-Coordinate where the watermark will be located.</param>
  16.     /// <param name="y">The Y-Coordinate where the watermark will be located.</param>
  17.     public static Image Mark(string location, string mark, int x, int y)
  18.     {
  19.         Image img = Image.FromFile(location);
  20.         Image image = new Bitmap(img.Width, img.Height);
  21.         Graphics G = Graphics.FromImage(image);
  22.         G.DrawImage(img, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
  23.         img.Dispose();
  24.         G.DrawString(mark, new Font("Arial", 20, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(Color.FromArgb(75, 0, 0, 0)), new Point(x,y));
  25.         G.Dispose();
  26.  
  27.         return image;
  28.     }
  29.     /// <summary>
  30.     /// WaterMark the image with another Image.
  31.     /// </summary>
  32.     /// <param name="location">Location of desired image.</param>
  33.     /// <param name="mark">The image used to watermark the desired image.</param>
  34.     /// <param name="x">The X-Coordinate where the watermark will be located.</param>
  35.     /// <param name="y">The Y-Coordinate where the watermark will be located.</param>
  36.     public static Image Mark(string location, Image markImage, int x, int y)
  37.     {
  38.         Image img = Image.FromFile(location);
  39.         Image image = new Bitmap(img.Width, img.Height);
  40.         Graphics G = Graphics.FromImage(image);
  41.         ColorMatrix cm = new ColorMatrix();
  42.         cm.Matrix00 = cm.Matrix11 = cm.Matrix22 = cm.Matrix44 = 1;
  43.         cm.Matrix33 = 0.3F;
  44.         ImageAttributes ia = new ImageAttributes();
  45.         ia.SetColorMatrix(cm);
  46.         G.DrawImage(img, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
  47.         img.Dispose();
  48.         G.DrawImage(markImage, new Rectangle(x, y, markImage.Width, markImage.Height), 0, 0, markImage.Width, markImage.Height, GraphicsUnit.Pixel, ia);            
  49.         G.Dispose();
  50.         return image;
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment