Adding text to Image using C# with ASP.NET | Image editing using c# with ASP.Net

Today i got a requirement to work on images, so i have tried to add the text to image... I am getting lot of errors. finally i got the solutions. In the output image i have added my blog name.Here we are doing operations based on System.Drawing name space.


Input                                                         Output:
Adding Text to image using c#.net
Adding Text to image using c#.net
Adding Text to image using c#.net output
Adding Text to image using c#.net output














Code: 
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 = @"D:\ranga.jpg";
        string outputImageFilePath = @"D:\OutPut.jpg";
        string textToDisplayOnImage = "www.aspnettutorialonline.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);
    }
}

Your comments are welcome for this post. 
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar