2011-11-23 11 views
6

Estoy buscando una biblioteca de animación .NET C# gif (no tiene que ser gratuita) que me permita tomar un archivo gif y adjuntarlo a un marco de jpeg o incluso a otro archivo gif. También necesitaré poder agregar el retraso cambiante entre los marcos. La respuesta a preguntas similares aquí generalmente hace referencia a una biblioteca básica que solo le permite agregar un retraso fijo entre imágenes estáticas.biblioteca gif avanzada

+0

Se cerró porque, como se le preguntó, era un duplicado. No mencionó la necesidad de cambiar la demora entre cuadros o que encontró respuestas anteriores que no satisfacían sus necesidades. :) –

+0

Estoy de acuerdo, simplemente no esperaba que se cerrara tan rápido :) –

+2

Por favor, no firme sus mensajes. –

Respuesta

7

Terminé modificando el código http://www.codeproject.com/KB/GDI-plus/NGif.aspx para obtener lo que necesitaba y funcionó! :)

para el manejo de archivos gif fuente añade que este método:

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

y en cuanto a los retrasos de aduana He modificado este método:

 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 
    } 

a resumir, - este el código puede agregar un gif como un marco dividiéndolo en cuadros y agregándolos, y también puede agregar retrasos personalizados.