2011-11-23 17 views
6

मैं एक .NET सी # gif एनीमेशन पुस्तकालय के लिए देख रहा हूँ (मुक्त होने के लिए नहीं है) कि मुझे एक gif फ़ाइल लेने के लिए और यह jpeg या यहां तक ​​कि एक और gif फ़ाइल का एक फ्रेम को संलग्न करने की अनुमति देगा। मुझे फ्रेम के बीच बदलती देरी जोड़ने में भी सक्षम होना चाहिए। यहां समान प्रश्नों का उत्तर आमतौर पर एक मूलभूत लाइब्रेरी का संदर्भ देता है जो केवल आपको स्थिर छवियों के बीच एक निश्चित देरी जोड़ने की अनुमति देता है।उन्नत gif पुस्तकालय

+0

यह बंद कर दिया गया था क्योंकि यह पूछा गया था, यह एक डुप्लिकेट था। आपने फ्रेम के बीच देरी को बदलने की आवश्यकता का जिक्र नहीं किया है या आपको पिछले उत्तरों मिले जो आपकी आवश्यकताओं को पूरा नहीं करते हैं। :) –

+0

मैं सहमत हूं, मैं बस इतना तेज़ बंद होने की उम्मीद नहीं कर रहा था :) –

+2

कृपया अपनी पोस्ट पर हस्ताक्षर नहीं करें। –

उत्तर

7

मैं मैं क्या उसे प्राप्त कर http://www.codeproject.com/KB/GDI-plus/NGif.aspx कोड को संशोधित करने समाप्त हो गया है और यह काम किया! :)

gif स्रोत फ़ाइल से निपटने के लिए

मैं इस विधि कहा:

 private bool AddGifFrames(Image image) 
    { 
     // implementation 

     var fd = new FrameDimension(image.FrameDimensionsList[0]); 
     int frameCount = image.GetFrameCount(fd); 

     var frames = new List<Tuple<int, Image>>(); 

     if (frameCount > 1) 
     { 
      frames = new List<Tuple<int, Image>>(); 

      //0x5100 is the property id of the GIF frame's durations 
      //this property does not exist when frameCount <= 1 
      byte[] times = image.GetPropertyItem(0x5100).Value; 

      for (int i = 0; i < frameCount; i++) 
      { 
       //selects GIF frame based on FrameDimension and frameIndex 
       image.SelectActiveFrame(fd, i); 

       //length in milliseconds of display duration 
       int length = BitConverter.ToInt32(times, 4 * i); 

       //save currect image frame as new bitmap 
       frames.Add(new Tuple<int, Image>(length, new Bitmap(image))); 
      } 
     } // Not animated 

     foreach (var frame in frames) 
     { 
      HandleFrame(frame.Item2, frame.Item1); 
     } 

     return true; 
    } 

और कस्टम देरी के लिए के रूप में मैं इस विधि संशोधित कर लिया है:

 protected void WriteGraphicCtrlExt(int? delay) 
    { 
     Fs.WriteByte(0x21); // extension introducer 
     Fs.WriteByte(0xf9); // GCE label 
     Fs.WriteByte(4); // data block size 
     int transp, disp; 
     if (Transparent == Color.Empty) 
     { 
      transp = 0; 
      disp = 0; // dispose = no action 
     } 
     else 
     { 
      transp = 1; 
      disp = 2; // force clear if using transparent color 
     } 
     if (Dispose >= 0) 
     { 
      disp = Dispose & 7; // user override 
     } 
     disp <<= 2; 

     // packed fields 
     Fs.WriteByte(Convert.ToByte(0 | // 1:3 reserved 
            disp | // 4:6 disposal 
            0 | // 7 user input - 0 = none 
            transp)); // 8 transparency flag 

     WriteShort(delay ?? Delay); // delay x 1/100 sec 
     Fs.WriteByte(Convert.ToByte(TransIndex)); // transparent color index 
     Fs.WriteByte(0); // block terminator 
    } 

यह योग अप करने के लिए - यह कोड फ्रेम को विभाजित करके उन्हें जोड़कर एक फ्रेम के रूप में एक gif जोड़ सकता है, और यह कस्टम देरी भी जोड़ सकता है।

संबंधित मुद्दे