Home > Articles > Writing Text on an image using C#.net & ASP.net  


Writing Text on an image using C#.net & ASP.net

This article will help you to understand how to write text on an image. any specified text can be written on a specified place on an image

//This is the image where we are going to write the text on it.
string stringMasterImageName = @"D:\MasterImage.jpg";
Bitmap bitmapMasterImage = new System.Drawing.Bitmap(stringMasterImageName);
Graphics graphicsMasterImage = Graphics.FromImage(bitmapMasterImage);

//Set the alignment based on the coordinates 
StringFormat stringformatWriteTextFormat = new StringFormat();
stringformatWriteTextFormat.Alignment = StringAlignment.Center;

//Set the font color
Color colorStringColor = System.Drawing.ColorTranslator.FromHtml("#000081");
string stringText = "Text Content Here";
graphicsMasterImage.DrawString(stringText, new Font("Tahoma", 30, 
FontStyle.Italic), new SolidBrush(colorStringColor), 
new Point(310, 260), stringformatWriteTextFormat);
Response.ContentType="image/jpeg";
bitmapMasterImage.Save(Response.OutputStream, ImageFormat.Jpeg);

//Save the new image in a physical location
string stringOutPutFileName = @"D:\\OutPut.jpg";
bitmapMasterImage.Save(stringOutPutFileName);


Welcome Guest
Sign In | Register