Put watermarks on uploaded images–ASP.NET

Here’s the simples piece of code in C# which can write some text on an image, eventually making it as a watermark.

StreamReader reader = new StreamReader(Server.MapPath("sample.jpg")); Bitmap bi = new Bitmap(reader.BaseStream); // base image Graphics gr = Graphics.FromImage(bi); string customString = "your string goes here"; gr.DrawString(s, new Font("Cooper Black", 25), Brushes.ForestGreen, new PointF(140, 115)); StreamWriter writer = new StreamWriter(Server.MapPath("edited.jpg")); writer.AutoFlush = true; bi.Save(writer.BaseStream, ImageFormat.Jpeg); // saving the edited image reader.Close(); writer.Close();

Advertisements

Comments are closed.

Powered by WordPress.com.

Up ↑

%d bloggers like this: