Exemple #1
0
        public override void EndScreenshot()
        {
            if (mScreenshotRenderTarget == null)
            {
                return;
            }

            ScreenshotRequests.ForEach(
                screenshotRequestStream =>
            {
                if (screenshotRequestStream == null)
                {
                    return;
                }

                mScreenshotRenderTarget.SaveAsPng(
                    screenshotRequestStream, mScreenshotRenderTarget.Width, mScreenshotRenderTarget.Height
                    );

                screenshotRequestStream.Close();
            }
                );

            ScreenshotRequests.Clear();

            if (mGraphicsDevice == null)
            {
                return;
            }

            var skippedFrame = mScreenshotRenderTarget;

            mScreenshotRenderTarget = null;
            mGraphicsDevice.SetRenderTarget(null);

            if (!Begin())
            {
                return;
            }

            mSpriteBatch?.Draw(skippedFrame, new XNARectangle(), XNAColor.White);
            End();
        }
Exemple #2
0
        public void RequestScreenshot(string screenshotDir = "screenshots")
        {
            if (!Directory.Exists(screenshotDir))
            {
                Directory.CreateDirectory(screenshotDir ?? "");
            }

            var    screenshotNumber = 0;
            string screenshotFile;

            do
            {
                screenshotFile = Path.Combine(
                    screenshotDir ?? "", $"{DateTime.Now:yyyyMMdd-HHmmssfff}{screenshotNumber}.png"
                    );

                ++screenshotNumber;
            } while (File.Exists(screenshotFile) && screenshotNumber < 4);

            ScreenshotRequests.Add(File.OpenWrite(screenshotFile));
        }