ASP. NET adds copyright information to images (watermarks images)

Source: Internet
Author: User

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 );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.