Program for watermarking Images Written N years ago:
/// <Summary>
/// Add the image copyright information to the image
/// </Summary>
/// <Param name = "strfilename"> input image (absolute path) </param>
/// <Param name = "stroutfilename"> output image (absolute path) </param>
/// <Param name = "strcopyrightfile"> watermark image (absolute path) </param>
/// <Param name = "strplace"> watermark position </param>
/// <Param name = "bolfilename"> whether to delete the input image </param>
Public static void createcopyrightimage (string strfilename, string stroutfilename, string strcopyrightfile, string strplace, bool bolfilename)
{
System. Drawing. Image myimage = system. Drawing. image. fromfile (strfilename );
System. Drawing. Image copymyimage = system. Drawing. image. fromfile (strcopyrightfile );
System. Drawing. Bitmap output = new system. Drawing. Bitmap (myimage );
System. Drawing. Graphics gimage = system. Drawing. Graphics. fromimage (output );
Int intx = 0;
Int inty = 0;
If (strplace = "1") // in the upper left corner
{
Intx = 0;
Inty = 0;
}
Else if (strplace = "2") // on the front
{
Intx = (myimage. Width-CopyMyImage.Width)/2;
Inty = 0;
}
Else if (strplace = "3") // in the upper right corner
{
Intx = myimage. Width-CopyMyImage.Width;
Inty = 0;
}
Else if (strplace = "4") // on the left
{
Intx = 0;
Inty = (myimage. Height-CopyMyImage.Height)/2;
}
Else if (strplace = "5") // in the middle
{
Intx = (myimage. Width-CopyMyImage.Width)/2;
Inty = (myimage. Height-CopyMyImage.Height)/2;
}
Else if (strplace = "6") // on the right
{
Intx = myimage. Width-CopyMyImage.Width;
Inty = (myimage. Height-CopyMyImage.Height)/2;
}
Else if (strplace = "7") // in the lower left corner
{
Intx = 0;
Inty = myimage. Height-CopyMyImage.Height;
}
Else if (strplace = "8") // at the bottom
{
Intx = (myimage. Width-CopyMyImage.Width)/2;
Inty = myimage. Height-CopyMyImage.Height;
}
Else if (strplace = "9") // in the lower right corner
{
Intx = myimage. Width-CopyMyImage.Width;
Inty = myimage. Height-CopyMyImage.Height;
}
Else
{
Intx = myimage. Width-CopyMyImage.Width-10;
Inty = myimage. Height-CopyMyImage.Height-10;
}
// Watermark position
Gimage. drawimage (copymyimage, intx, inty, copymyimage. Width, copymyimage. Height );
String strextend = strfilename. substring (strfilename. lastindexof (".") + 1). tolower ();
Switch (strextend)
{
Case "BMP ":
Output. Save (stroutfilename, system. Drawing. imaging. imageformat. BMP );
Break;
Case "jpg ":
Output. Save (stroutfilename, system. Drawing. imaging. imageformat. JPEG );
Break;
Case "GIF ":
Output. Save (stroutfilename, system. Drawing. imaging. imageformat. GIF );
Break;
Case "icon ":
Output. Save (stroutfilename, system. Drawing. imaging. imageformat. Icon );
Break;
Case "PNG ":
Output. Save (stroutfilename, system. Drawing. imaging. imageformat. PNG );
Break;
Case "TIF ":
Output. Save (stroutfilename, system. Drawing. imaging. imageformat. Tiff );
Break;
Default:
Output. Save (stroutfilename, system. Drawing. imaging. imageformat. JPEG );
Break;
}
Gimage. Dispose ();
Output. Dispose ();
Myimage. Dispose ();
Copymyimage. Dispose ();
If (bolfilename)
File. Delete (strfilename );
}