示例#1
0
        public void ExportSequence(string directory, int framedelay, bool resize = false)
        {
            if (Playing)
            {
                /*Playing = false;
                 * textBox3.Enabled = true;
                 * textBox4.Enabled = true;
                 * pictureBox1.Focus();*/
                StopPlayback();
            }

            /*if (thetimer != null)
             * {
             *  thetimer.Dispose();
             *  thetimer = null;
             * }*/
            timer1.Stop();
            bool started = false;
            //int fps = (int)float.Parse(S.textBox1.Text);
            int fps = framedelay;

            forcetime = fps;
            CD        = 0;

            ComicPanel CP = (ComicPanel)F.panel1.Controls[0];

            F.SelectedPanel.Unselect();

            /*try
             * {
             *  F.panel1.VerticalScroll.Value = 0;
             * }
             * catch
             * {
             * }*/
            CP.Select();

            int frame = 0;

            int            lastpanel = -1;
            MemoryStream   MS        = null;
            ProgressWindow PW        = new ProgressWindow();

            PW.Show();
            ProgressBar PB = PW.progressBar1;

            PB.Maximum = F.panel1.Controls.Count;
            PB.Step    = 1;
            PW.Text    = "Exporting sequence... Framerate:" + (int)(1000f / fps);
            Size first = Size.Empty;

            //PW.label1.Text = "Exporting your frame sequence please wait...";
            while (!started /* || CurrentDelay!=0*/ || F.SelectedPanel.ind != 0)
            {
                //started = true;
                timer1_Tick(null, null);
                if (!started || F.SelectedPanel.ind != 0)
                {
                    if (F.SelectedPanel.ind != 0)
                    {
                        started = true;
                    }
                    if (F.SelectedPanel.ind != lastpanel)
                    {
                        Bitmap TB    = F.img[F.SelectedPanel.ind];
                        int    W     = TB.Width - (TB.Width & 1);
                        int    H     = TB.Height - (TB.Height & 1);
                        Bitmap B     = TB;
                        bool   clone = false;
                        if (first.IsEmpty)
                        {
                            first.Width  = W;
                            first.Height = H;
                        }
                        else if (resize)
                        {
                            W = first.Width;
                            H = first.Height;
                        }
                        if (B.Width != W || B.Height != H)
                        {
                            //B = TB.Clone(new Rectangle(0, 0, W, H), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                            Size     s   = new Size(W, H);
                            Bitmap   ret = new Bitmap(s.Width, s.Height);
                            Graphics G   = Graphics.FromImage(ret);
                            Point    P   = Point.Empty;
                            //Point P = new Point((int)(B.Size.Width * (IX * 0.01)), (int)(B.Size.Height * (IY * 0.01)));
                            //Size Sz = new Size((int)(B.Size.Width * (IWidth * 0.01)), (int)(B.Size.Height * (IHeight * 0.01)));
                            Size Sz = s;
                            G.DrawImage(B, new Rectangle(Point.Empty, ret.Size), new Rectangle(P, Sz), GraphicsUnit.Pixel);
                            G.Dispose();
                            B = ret;
                            //return ret;

                            clone = true;
                        }
                        Bitmap temp = B;
                        if (F.Cropper.IWidth != 100 && F.Cropper.IHeight != 100)
                        {
                            B = F.Crop(B);
                        }
                        if (temp != B && temp != TB)
                        {
                            temp.Dispose();
                        }
                        temp = B;
                        B    = F.GetStretch(B);
                        if (temp != B && temp != TB)
                        {
                            temp.Dispose();
                        }
                        temp = null;
                        //B = F.GetStretch(F.Crop(B));
                        clone = true;

                        //B.Save(directory + "/frame" + ("" + frame).PadLeft(5, '0') + ".png");
                        if (MS != null)
                        {
                            MS.Dispose();
                        }
                        MS = new MemoryStream();
                        B.Save(MS, System.Drawing.Imaging.ImageFormat.Png);
                        if (clone && B != TB)
                        {
                            B.Dispose();
                        }
                        B = null;
                        PB.PerformStep();
                        PW.Invalidate();
                        GC.Collect();
                    }
                    using (var fileStream = File.Create(directory + "/frame" + ("" + frame).PadLeft(5, '0') + ".png"))
                    {
                        MS.Seek(0, SeekOrigin.Begin);
                        MS.CopyTo(fileStream);
                    }
                    frame++;
                }
            }
            PW.Close();
            PW.Dispose();
            forcetime = 0;
            timer1.Start();


            //thetimer = new System.Threading.Timer((a) => { pictureBox1.Invalidate(); }, null, 0, 10);
        }