Advertisement
Guest User

Untitled

a guest
May 25th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1.         public static void Watermark (string imageUrl)
  2.         {
  3.             Stopwatch watch = new Stopwatch ();
  4.             watch.Start ();
  5.  
  6.             Console.WriteLine ("Starting process");
  7.             string BASE = Directory.GetCurrentDirectory () + "/Images/";
  8.  
  9.             WebClient client = new WebClient ();
  10.             byte[] data = client.DownloadData (imageUrl);
  11.             Console.WriteLine ("Elapsed: " + watch.ElapsedMilliseconds);
  12.  
  13.             using (Image image = Image.FromStream (new MemoryStream (data)))
  14.             using (Image watermark = Image.FromFile (BASE + "watermark.png"))
  15.             using (Graphics graphics = Graphics.FromImage (image))
  16.             using (Brush brush = new TextureBrush (watermark)) {
  17.  
  18.                 int x = (image.Width - watermark.Width)/2;
  19.                 int y = (image.Height - watermark.Height)/2;
  20.  
  21.                 graphics.FillRectangle(brush, new Rectangle(new Point(x, y), watermark.Size));
  22.                 image.Save(BASE + "norma_watermarked.jpg");
  23.             }
  24.  
  25.             watch.Stop ();
  26.             Console.WriteLine ("Process ended: " + watch.ElapsedMilliseconds);
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement