我有一個創建一個GIF動畫功能,它總是完美的工作,但現在當我所有的GIF圖像是黑白的,它提供了一個內存溢出的例外論:內存異常
e.AddFrame(圖像。 FROMFILE(imageFilePaths [I]));
我的功能:
public void MakeGif(string sourcefolder, string destinationgif)
{
IsGifing = true;
string path = MainForm.RootDirectory;
String[] imageFilePaths = Directory.GetFiles(path);
String outputFilePath = MainForm.RootDirectory + @"\Final.gif";
AnimatedGifEncoder e = new AnimatedGifEncoder();
e.Start(outputFilePath);
e.SetDelay(300);
//-1:no repeat,0:always repeat
e.SetRepeat(0);
for (int i = 0, count = imageFilePaths.Length; i < count; i++)
e.AddFrame(Image.FromFile(imageFilePaths[i]));
e.Finish();
IsGifing = false;
}
ADDFRAME功能:
public bool AddFrame(Image im)
{
if ((im == null) || !started)
{
return false;
}
bool ok = true;
try
{
if (!sizeSet)
{
// use first frame's size
SetSize(im.Width, im.Height);
}
image = im;
GetImagePixels(); // convert to correct format if necessary
AnalyzePixels(); // build color table & map pixels
if (firstFrame)
{
WriteLSD(); // logical screen descriptior
WritePalette(); // global color table
if (repeat >= 0)
{
// use NS app extension to indicate reps
WriteNetscapeExt();
}
}
WriteGraphicCtrlExt(); // write graphic control extension
WriteImageDesc(); // image descriptor
if (!firstFrame)
{
WritePalette(); // local color table
}
WritePixels(); // encode and write pixel data
firstFrame = false;
}
catch (IOException e)
{
ok = false;
}
return ok;
}
感謝您的回答。注意:這不是因爲黑白GIF,我正在查看錯誤的文件夾並嘗試添加.txt文件> _> – 2011-05-27 20:00:01