How to add a picture watermark to a. NET C # gif animation ideas and code _ practical skills

Source: Internet
Author: User
Copy Code code as follows:

public static Bitmap Watermarkwithtext (System.Drawing.Bitmap origialgif, string
Text,string FilePath)
{
For storing hardwood
List<frame> frames = new
List<frame> ();
If not a GIF file, return directly to the original image
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 ("Song Body"), 35.0f,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.