Beispiel #1
0
        public void SaveAsGIF(string path, GIFQuality quality)
        {
            if (imgCache != null && imgCache is HardDiskCache && !IsRecording)
            {
                HardDiskCache hdCache = imgCache as HardDiskCache;

                using (GifCreator gifEncoder = new GifCreator(delay))
                {
                    int i     = 0;
                    int count = hdCache.Count;

                    foreach (Image img in hdCache.GetImageEnumerator())
                    {
                        i++;
                        OnEncodingProgressChanged((int)((float)i / count * 100));

                        using (img)
                        {
                            gifEncoder.AddFrame(img, quality);
                        }
                    }

                    gifEncoder.Finish();
                    gifEncoder.Save(path);
                }
            }
        }
Beispiel #2
0
        //Save
        private void btn_save_Click(object sender, EventArgs e)
        {
            //Check whether the file already exist

            {
                if (new System.IO.FileInfo(path).Exists)
                {
                    string defpath = path.Substring(0, path.LastIndexOf('.'));
                    int    counter = 2;
                    string ext     = path.Substring(path.LastIndexOf('.'));
                    path = defpath + " (" + counter.ToString() + ")" + ext;

                    while ((new System.IO.FileInfo(path)).Exists)
                    {
                        counter += 1;
                        path     = path.Substring(0, path.Length - 7) + "(" + counter.ToString() + ")" + ext;
                    }


                    //Info
                    string msg = "A file with the name \"" + defpath + ext + "\" does already exist. Do you want to rename the file into \"" + path + "\"?";

                    if ((MessageBox.Show(msg, "File already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != System.Windows.Forms.DialogResult.Yes))
                    {
                        return;
                    }
                }


                Bitmap bmp;

                //Save the current gen
                bool[,] currgen = Attributes.Cells;

                //Save
                switch (safetype)
                {
                case SafeTypes.Bitmap:

                    bmp = new Bitmap(AFieldOfLife.Width, AFieldOfLife.Height);
                    Attributes.Cells = Attributes.CurrentCellStack.ToArray()[Attributes.CurrentCellStack.Count - 1 - gen];

                    AFieldOfLife.DrawOnGfx(Graphics.FromImage(bmp));
                    bmp.Save(path);

                    break;

                case SafeTypes.GIF:

                    List <Bitmap> bmplist = new List <Bitmap>();
                    foreach (bool[,] generation in Attributes.CurrentCellStack)
                    {
                        Attributes.Cells = generation;
                        bmp = new Bitmap(AFieldOfLife.Width, AFieldOfLife.Height);
                        AFieldOfLife.DrawOnGfx(Graphics.FromImage(bmp));

                        //to get longer intervals
                        bmplist.Add(bmp);
                        bmplist.Add(bmp);
                    }

                    GifCreator.Save(bmplist, path);

                    break;

                case SafeTypes.Data:

                    //Save the data in a textfile

                    using (System.IO.StreamWriter streamw = new System.IO.StreamWriter(new System.IO.FileStream(path, System.IO.FileMode.CreateNew), System.Text.Encoding.UTF8))
                    {
                        streamw.WriteLine(Attributes.AmountOfCellsPerLine.ToString());

                        bool[,] gentowrite = Attributes.CurrentCellStack.ToArray()[Attributes.CurrentCellStack.Count - 1 - gen];

                        for (int i = 0; i <= gentowrite.GetUpperBound(0); i++)
                        {
                            for (int j = 0; j <= gentowrite.GetUpperBound(1); j++)
                            {
                                streamw.Write(Convert.ToInt32(gentowrite[j, i]).ToString() + " ");
                            }
                            streamw.WriteLine();
                        }
                    }


                    break;
                }

                //Restore last gen
                Attributes.Cells = currgen;

                this.Close();
            }
        }