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