Here i describe how to draw sting on any image. in that i used graphics class for that you can call this function in the page load or any button event and you have to just pass the string which you want to draw on the image. this way
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { AddWatermark("Demo version"); } }
public void AddWatermark(string watermarkText) { System.Drawing.Image bitmap = (System.Drawing.Image)Bitmap.FromFile(Server.MapPath("image\\img_tripod.jpg"));
Font font = new Font("Arial", 20, FontStyle.Italic, GraphicsUnit.Pixel);
Color color = Color.FromArgb(255, 255, 0, 0); Point atpoint = new Point(bitmap.Width / 2, bitmap.Height / 2); SolidBrush brush = new SolidBrush(color); Graphics graphics = Graphics.FromImage(bitmap);
StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center;
graphics.DrawString(watermarkText, font, brush, atpoint,sf); graphics.Dispose(); MemoryStream m = new MemoryStream(); bitmap.Save(m, System.Drawing.Imaging.ImageFormat.Jpeg); m.WriteTo(Response.OutputStream); m.Dispose(); base.Dispose(); }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|