Saturday, 21 April 2012

Adding a simple text watermark to an image

if (pictureBox1.Image != null)
{
    //Create image.
    Image tmp = pictureBox1.Image;
    //Create graphics object for alteration.
    Graphics g = Graphics.FromImage(tmp);

    //Create string to draw.
    String wmString = "Code Project";
    //Create font and brush.
    Font wmFont = new Font("Trebuchet MS", 10);
    SolidBrush wmBrush = new SolidBrush(Color.Black);
    //Create point for upper-left corner of drawing.
    PointF wmPoint = new PointF(10.0F, 10.0F);
    //Draw string to image.
    g.DrawString(wmString, wmFont, wmBrush, wmPoint);
    //Load the new image to picturebox
    pictureBox1.Image= tmp;       
    //Release graphics object.
    g.Dispose();               
}

No comments:

Post a Comment