Initial Implementation of adding a watermark to gif Animation

Source: Internet
Author: User
Post it first:
Original GIF image:

Image after adding a text watermark

Herosoft is the added watermark.
Handling ideas:
Obtain each GIF image and add it as a watermark to obtain the delay time of each GIF image. Generate a custom frame object. After processing each frame, add the GIF parameter information to these images through the program and generate a new GIF file, currently, the ngif library is used to generate GIF files, which is very slow. Looking for a better solution
Program Of Code Yes, and there is a DLL reference 1 Public   Static Bitmap watermarkwithtext (system. Drawing. Bitmap origialgif, String Text, String Filepath)
2 {
3 // Used to store shards
4 List < Frame > Frames =   New List < Frame > ();
5 // If it is not a GIF file, the original image is returned directly.
6 If (Origialgif. rawformat. guid ! = System. Drawing. imaging. imageformat. gif. guid)
7 {
8ReturnOrigialgif;
9}
10 // If the image is a GIF File
11 Foreach (Guid In Origialgif. framedimensionslist)
12 {
13 System. Drawing. imaging. framedimension =   New System. Drawing. imaging. framedimension (guid );
14 Int Framecount = Origialgif. getframecount (framedimension );
15 For ( Int I =   0 ; I < Framecount; I ++ )
16 {
17 If (Origialgif. selectactiveframe (framedimension, I) =   0 )
18 {
19 Int Delay = Convert. toint32 (origialgif. getpropertyitem ( 20736 ). Value. getvalue (I ));
20 Image img = Image. fromhbitmap (origialgif. gethbitmap ());
21 Font font =   New Font ( New Fontfamily ( " " ), 35366f , Fontstyle. Bold );
22 Graphics g = Graphics. fromimage (IMG );
23 G. drawstring (text, Font, brushes. blanchedalmond, New Pointf ( 10.0f , 10.0f ));
24 Frame =   New Frame (IMG, delay );
25 Frames. Add (FRAME );
26 }
27 }
28 GIF. components. animatedgifencoder GIF =   New GIF. components. animatedgifencoder ();
29 GIF. Start (filepath );
30 GIF. setdelay ( 100 );
31 GIF. setrepeat ( 0 );
32 For ( Int I =   0 ; I < Frames. Count; I ++ )
33 {
34GIF. addframe (frames [I]. Image );
35}
36 GIF. Finish ();
37 Try
38 {
39 Bitmap gifimg = (Bitmap) bitmap. fromfile (filepath );
40 Return Gifimg;
41 }
42 Catch
43 {
44ReturnOrigialgif;
45}
46 }
47 Return Origialgif;
48 }

Currently, my implementation has several problems:
1) unable to process GIF with transparent background
2) processing speed is quite slow
Brothers, give more comments and solve this problem. The efficiency problem is serious. At present, it cannot reach the application level because it is too slow. Every GIF image is generated for about 4-10 s.

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.