1

私はアニメーションGIFを作成する機能を持っています.常に完璧に機能しましたが、すべてのGIFが白黒の場合、 OutOfMemory Exception On が発生します:

e.AddFrame(Image.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;
    }
4

2 に答える 2

0

詳細はわかりませんが、これは書き込みのようには見えません。「使用」がないため、リソースを破棄していない可能性があります。

于 2011-05-27T19:18:40.890 に答える