How to write text on image using asp.net


In this article I'm going to explain how to write text on image and save that save in new location. Without third part control I'm going to write text on image control. You need to import below name spaces in your code behind file. You need to import below name spaces to run below code 1)System.Drawing.Imaging 2)System.Drawing 3)using System;

In this article I'm going to explain how to write text on image and save that save in new location. Without third part control I'm going to write text on image control. You need to import below name spaces in your code behind file.

You need to import below name spaces to run below code

1)System.Drawing.Imaging
2)System.Drawing
3)using System;





using System;
using System.Drawing;
using System.Drawing.Imaging;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//By using below statement where we are going get image to write the text on it.
string strMasterImagePath = @"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg";
Bitmap bitmapMasterImages = new System.Drawing.Bitmap(strMasterImagePath);
Graphics graphicsMasterImages = Graphics.FromImage(bitmapMasterImages);

//By using below statement we can Set the alignment based on the coordinates
StringFormat strformatWriteTextFormat = new StringFormat();
strformatWriteTextFormat.Alignment = StringAlignment.Center;

//By using below statement we are going to Set the font color
Color clrStringColor = System.Drawing.ColorTranslator.FromHtml("#000091");
string strText = "Editor of Dotnetspider" + Environment.NewLine + "Regards" + Environment.NewLine + "UltimateRengan";
graphicsMasterImages.DrawString(strText, new Font("Tahoma", 40,
FontStyle.Italic), new SolidBrush(clrStringColor),
new Point(320, 270), strformatWriteTextFormat);
Response.ContentType = "image/jpeg";
bitmapMasterImages.Save(Response.OutputStream, ImageFormat.Jpeg);

//By using below statement we are going to Save the new image in a below location
string strOutPutFilePath = @"C:\Users\Public\Pictures\Sample Pictures\DNS.jpg";
bitmapMasterImages.Save(strOutPutFilePath);
}
}


Comments

Author: jayaprathap06 Dec 2013 Member Level: Bronze   Points : 0


its working but i am not able to write the text on image,i have save the file not in correct format ! can you please tell ?



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: