需要用到一个NGif的库,是国人编写的,不过到我写这个帖子的时候还不是以dll文件的方式提供,是给出的代码。这里我编译了一个dll.
http://files.cnblogs.com/sitt/NGifDll.zip
这个dll文件需要和脚本在同目录执行,脚本需要保存下,或者读者自己修改一下DotNet.LoadAssembly
简单的生成Gif的MaxScript如下
生成Gif
localPath = GetFilenamePath (GetSourceFileName())
DotNet.LoadAssembly (localPath + "Ngif.dll")
GifEncoder = DotNetObject "NGif.AnimatedGifEncoder"
DotNetImage = DotNetClass "System.Drawing.Image"
theGifFileName = "d:\\test.gif"
gifFrames = #("d:\\01.png","d:\\02.png","d:\\03.png")
GifEncoder.Start(theGifFileName )
GifEncoder.SetDelay(500);
GifEncoder.SetRepeat(0);
for tempframe in gifFrames do
(
tempImage = DotNetImage.FromFile tempframe
GifEncoder.AddFrame tempImage
tempImage.Dispose()
)
GifEncoder.Finish()
渲染至Gif
localPath = GetFilenamePath (GetSourceFileName())
DotNet.LoadAssembly (localPath + "Ngif.dll")
GifEncoder = DotNetObject "NGif.AnimatedGifEncoder"
DotNetImage = DotNetClass "System.Drawing.Image"
theGifFileName = "d:\\test.gif"
GifEncoder.Start(theGifFileName )
GifEncoder.SetDelay(40);
GifEncoder.SetRepeat(0);
timeStart = AnimationRange.Start.Frame
timeEnd = AnimationRange.End.Frame
for i = timeStart to timeEnd do
(
SliderTime = i
tempframe = "d:\\test.png"
render outputfile:tempframe vfb:false
tempImage = DotNetImage.FromFile tempframe
GifEncoder.AddFrame tempImage
tempImage.Dispose()
)
GifEncoder.Finish()