Пример #1
0
        public static PictureRenderCore CreateRenderCore()
        {
            BrowserSettings browserSettings = new BrowserSettings
            {
                WindowlessFrameRate = 1
            };

            PictureRenderCore core = new PictureRenderCore
            {
                _browser = new ChromiumWebBrowser(
                    Config.Current.PictureRenderAddress,
                    browserSettings,
                    new RequestContext())
            };

            core._browser.FrameLoadEnd += (sender, args) =>
                                          args.Frame.ExecuteJavaScriptAsync("document.body.style.background = 'transparent';");

            core._browser.BrowserInitialized += (sender, args) => core._resetFlag.Set();

            return(core);
        }
Пример #2
0
        static void RenderDoWork(object sender, DoWorkEventArgs args)
        {
            if (!(sender is ProgressDialog dialog))
            {
                return;
            }

            if (!(args.Argument is List <KeyValuePair <string, Mallow> > mallows))
            {
                return;
            }

            if (dialog.CancellationPending)
            {
                return;
            }

            dialog.ReportProgress(0, "准备导出…", "加载渲染组件");

            PictureRenderCore renderCore = PictureRenderCore.CreateRenderCore();

            if (dialog.CancellationPending)
            {
                renderCore.Dispose();
                return;
            }

            dialog.ReportProgress(0, "准备导出…", "加载展示场景");

            renderCore.LoadFrame();

            for (int index = 0; index < mallows.Count; index++)
            {
                if (dialog.CancellationPending)
                {
                    renderCore.Dispose();
                    return;
                }

                dialog.ReportProgress((int)Math.Floor(index * 100 / (double)mallows.Count), "正在导出图片…",
                                      $"第{index}个,共{mallows.Count}个");

                string fileName = mallows[index].Key;
                Mallow mallow   = mallows[index].Value;

                bool pushed = false;
                WebPush.Current.PushMallow(mallow, () => pushed = true);

                while (true)
                {
                    if (pushed)
                    {
                        break;
                    }
                }

                Task <Bitmap> task = renderCore.Capture();
                task.Wait();
                task.Result.Save(fileName);
            }

            dialog.ReportProgress(100, "正在导出图片…", "正在清理");

            renderCore.Dispose();

            //dialog.Dispose();
        }