日期:2010-01-02  浏览次数:20424 次

合成GIF

  1. /* create Gif */ 
  2. //you should replace filepath  
  3. String [] imageFilePaths = new String[]{"c:\\01.png","c:\\02.png","c:\\03.png"};  
  4. String outputFilePath = "c:\\test.gif";  
  5. AnimatedGifEncoder e = new AnimatedGifEncoder();  
  6. e.Start( outputFilePath );  
  7. e.SetDelay(500);  
  8. //-1:no repeat,0:always repeat  
  9. e.SetRepeat(0);  
  10. for (int i = 0, count = imageFilePaths.Length; i < count; i++ )  
  11. {  
  12.     e.AddFrame( Image.FromFile( imageFilePaths[i] ) );  
  13. }  
  14. e.Finish();  
  15. /* extract Gif */ 
  16. string outputPath = "c:\\";  
  17. GifDecoder gifDecoder = new GifDecoder();  
  18. gifDecoder.Read( "c:\\test.gif" );  
  19. for ( int i = 0, count = gifDecoder.GetFrameCount(); i < count; i++ )  
  20. {  
  21.     Image frame = gifDecoder.GetFrame( i ); // frame i  
  22.     frame.Save( outputPath + Guid.NewGuid().ToString() + ".png", ImageFormat.Png );  
  23. }  
  24.