In this web programming tutorial we will learn that how we can add some text on an image in asp.net using c#.just copy and page the code and add it in your .cs file.
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System;
public partial class About : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string inputImage = @"E:\color.jpg";
string outputImageFilePath = @"E:\Resultimage.jpg";
string textToDisplayOnImage = "www.webhealer.blogspot.com/";
Bitmap imageInBitMap = new Bitmap(inputImage);
Graphics imageGraphics = Graphics.FromImage(imageInBitMap);
//Set the alignment based on the coordinates
StringFormat formatAssignment= new StringFormat();
formatAssignment.Alignment = StringAlignment.Near;
//Here we are going to assign the font color
Color assignColorToString = System.Drawing.ColorTranslator.FromHtml("#000000");
//Assigning font size, font family, position of the text to display and others.
imageGraphics.DrawString(textToDisplayOnImage, new Font("Times new Roman", 8, FontStyle.Bold), new SolidBrush(assignColorToString), new Point(100, 150), formatAssignment);
//saving in the computer
imageInBitMap.Save(outputImageFilePath);
}
}
Tags:
asp.net