Add a copyright watermark to the image

Source: Internet
Author: User
Tags set background
We sometimes need to add copyright watermarks to images on the website. The. Net Graphics class can easily implement this.

(The line at the top of the image is the copyright watermark we added)

Implementation Code : /**/ /// <Summary>
///Generate an image with a copyright watermark
/// </Summary>
/// <Param name = "iconimg">File address of the watermark image to be generated</Param>
Private   Void Makewatermark ( String Iconimg)
{
// Define output bitmap
Bitmap BMP =   New Bitmap ( 640 , 480 );
// Define a Drawing Object
Graphics g = Graphics. fromimage (BMP );
// Describes the rectangular area of a drawing.
Rectangle newrect =   New Rectangle ( 0 , 0 , 640 , 480 );
// Set background color
G. fillrectangle ( New Solidbrush (color. White), newrect );
// Obtain the image to generate the watermark
Bitmap newbitmap =   New Bitmap (iconimg );
G. drawimage (newbitmap, 16 , 16 );
// Define the font of the watermark
Font font =   New Font (
" Arial " ,
12 ,
Fontstyle. Bold
);
// Define a style brush for water Printing
Lineargradientbrush brush =   New Lineargradientbrush (
New Rectangle ( 0 , 0 , 71 , 23 ),
Color. Red,
Color. Blue,
30f,
True
);
// Watermarks a photo
G. drawstring ( " Copyright by test. "   + System. datetime. Now. tow.datestring (), Font, brush, 0 , 0 );
// Save as a new output image
MS for system. Io. memorystream =   New System. Io. memorystream ();
BMP. Save (MS, imageformat. JPEG );

// Output Image
Response. clearcontent ();
Response. contenttype =   " Image/JPEG " ;
Response. binarywrite (Ms. toarray ());
}

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.