Draw text on an Image : Image : Graphics C# Source Code


Custom Search

C# Source Code » Graphics » Image »

 

Draw text on an Image








    
 

using System;
using System.Drawing;
using System.Windows.Forms;
   
class DrawOnImage: Form
{
     Image  image = Image.FromFile("Color.jpg");
     string str = "www.navioo.com";
   
     public static void Main()
     {
          Application.Run(new DrawOnImage());
     }
     public DrawOnImage()
     {
          ResizeRedraw = true; 
          Graphics grfxImage = Graphics.FromImage(image);
   
          grfxImage.PageUnit = GraphicsUnit.Inch;
          grfxImage.PageScale = 1;
   
          SizeF sizef = grfxImage.MeasureString(str, Font);
   
          grfxImage.DrawString(str, Font, Brushes.White, grfxImage.VisibleClipBounds.Width - sizef.Width, 0);
   
          grfxImage.Dispose();
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
     }       
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
     {
          grfx.PageUnit = GraphicsUnit.Pixel;
          grfx.DrawImage(image, 0, 0);
          grfx.DrawString(str, Font, new SolidBrush(clr),
                    grfx.DpiX * image.Width / image.HorizontalResolution, 0);
     }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Graphics
» Image