How to add image watermarks to. net c # GIF Animation

Source: Internet
Author: User

Copy codeThe Code is as follows: public static Bitmap WaterMarkWithText (System. Drawing. Bitmap origialGif, string
Text, string filePath)
{
// Used to store shards
List <Frame> frames = new
List <Frame> ();
// Directly return the original image if it is not a gif File
If (origialGif. RawFormat. Guid
! = System. Drawing. Imaging. ImageFormat. Gif. Guid)
{
Return origialGif;

}
// If the image is a gif File
Foreach (Guid guid in
OrigialGif. FrameDimensionsList)
{
System. Drawing. Imaging. FrameDimension
FrameDimension = new System. Drawing. Imaging. FrameDimension (guid );
Int
FrameCount = origialGif. GetFrameCount (frameDimension );
For (int I = 0; I
<FrameCount; I ++)
{
If (origialGif. SelectActiveFrame (frameDimension,
I) = 0)
{
Int delay =
Convert. ToInt32 (origialGif. GetPropertyItem (20736). Value. GetValue (I ));
Image
Img = Image. FromHbitmap (origialGif. GetHbitmap ());
Font font = new Font (new
FontFamily (""), 35366f, FontStyle. Bold );
Graphics g =
Graphics. FromImage (img );
G. DrawString (text, font, Brushes. BlanchedAlmond,
New PointF (10.0f, 10.0f ));
Frame frame = new Frame (img, delay );

Frames. Add (frame );
}
}
Gif. Components. AnimatedGifEncoder gif =
New Gif. Components. AnimatedGifEncoder ();
Gif. Start (filePath );

Gif. SetDelay (100 );
Gif. SetRepeat (0 );
For (int I = 0; I <
Frames. Count; I ++)
{
Gif. AddFrame (frames [I]. Image );
}

Gif. Finish ();
Try
{
Bitmap gifImg =
(Bitmap) Bitmap. FromFile (filePath );
Return gifImg;
}
Catch
{

Return origialGif;
}
}
Return origialGif;
}

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.