Beispiel #1
0
        public static void SaveCanvas()
        {
            string file = FileOperations.ShowSaveDialog("Экспорт PNG", ".png", "Export screen", FileOperations.FilterPng);

            if (string.IsNullOrEmpty(file))
            {
                return;
            }
            IncRender          ik   = MWin.I.iCanv;
            Image              im   = (Image)ik.Children[0];
            int                left = (int)InkCanvas.GetLeft(im);
            int                top  = (int)InkCanvas.GetTop(im);
            RenderTargetBitmap rtb  = new RenderTargetBitmap((int)(im.ActualWidth + left), (int)(im.ActualHeight + top), 96, 96, PixelFormats.Pbgra32);

            rtb.Render(MWin.I.iCanv);
            CroppedBitmap    crop = new CroppedBitmap(rtb, new Int32Rect(left, top, rtb.PixelWidth - left, rtb.PixelHeight - top));
            PngBitmapEncoder enc  = new PngBitmapEncoder();

            enc.Frames.Add(BitmapFrame.Create(crop));
            using (FileStream stm = File.Create(file)) {
                enc.Save(stm);
            }
            Logging.Log.Write("Конвертировано в png, файл - " + file);
        }
Beispiel #2
0
        public static void SaveVideo()
        {
            string file = FileOperations.ShowSaveDialog("Экспорт видео", ".avi", "Export screen", FileOperations.FilterAvi);

            if (string.IsNullOrEmpty(file))
            {
                return;
            }
            IncRender          ik = MWin.I.iCanv;
            RenderTargetBitmap rtb = null;
            int left = 0, top = 0;

            for (int i = 0; i < ik.Children.Count; i++)
            {
                if (ik.Children[i].GetType() == typeof(Image))
                {
                    Image im = (Image)ik.Children[i];
                    left = (int)InkCanvas.GetLeft(im);
                    top  = (int)InkCanvas.GetTop(im);
                    if (im.Tag.ToString() == "Back")
                    {
                        rtb = new RenderTargetBitmap((int)(im.ActualWidth + left), (int)(im.ActualHeight + top), 96, 96, PixelFormats.Pbgra32);
                    }
                    break;
                }
            }
            List <IAtimate> lst = ik.GetAnimables();

            if (lst.Count == 0)
            {
                MessageBox.Show("Нет анимируемых компонентов!");
                return;
            }
            MWin.I.IsEnabled = false;
            const double fps            = 24;
            double       leng           = MWin.I.sldTime.Maximum;
            const double inkr           = 1 / fps;
            int          numTotalFrames = (int)(fps * leng);

            AviRender.AviManager aviMan = new AviRender.AviManager(file, false);
            try {
                if (rtb != null)
                {
                    System.Drawing.Bitmap tmBmp     = new System.Drawing.Bitmap(rtb.PixelWidth, rtb.PixelHeight);
                    AviRender.VideoStream aviStream = aviMan.AddVideoStream(true, fps, tmBmp);
                    for (int i = 0; i < numTotalFrames; i++)
                    {
                        ik.PlayTime = i * inkr;
                        rtb.Render(ik);
                        CroppedBitmap crop = new CroppedBitmap(rtb, new Int32Rect(left, top, rtb.PixelWidth - left, rtb.PixelHeight - top));
                        tmBmp = ConvertBmp(crop);
                        aviStream.AddFrame(tmBmp);
                    }
                }
                Logging.Log.Write("Конвертировано в видео, файл - " + file);
                MessageBox.Show("Конвертирование завершено", "Завершено", MessageBoxButton.OK, MessageBoxImage.Information);
            } catch {
                Logging.Log.Write("Ошибка конвертирования");
                MessageBox.Show("Ошибка конвертирования\nВозможно стоит использовать другой кодек!\n" +
                                "Рекомендуется Microsoft Video 1", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            } finally {
                aviMan.Close();
            }
            MWin.I.IsEnabled = true;
        }