Пример #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            #region Set up screenshots
            if (isScreenshot)
            {
                Color[] screenData = new Color[GraphicsDevice.PresentationParameters.BackBufferWidth *
                                           GraphicsDevice.PresentationParameters.BackBufferHeight];

                screenShot = new RenderTarget2D(GraphicsDevice,
                    GraphicsDevice.PresentationParameters.BackBufferWidth,
                    GraphicsDevice.PresentationParameters.BackBufferHeight);

                GraphicsDevice.SetRenderTarget(screenShot);

                map.Draw(spriteBatch);
                base.Draw(gameTime);

                GraphicsDevice.SetRenderTarget(null);

                //save to disk
                string fileName = DateTime.Now.ToString();
                fileName = fileName.Replace('/', '-');
                fileName = fileName.Replace(':', '-');

                Stream stream = File.OpenWrite("\\Screens\\" + fileName + ".jpg");
                screenShot.SaveAsJpeg(stream,
                                        1280,
                                        720);
                stream.Dispose();
                screenShot.Dispose();

                //reset the screenshot flag
                isScreenshot = false;
            }
            #endregion

            map.Draw(spriteBatch);
            base.Draw(gameTime);
        }
Пример #2
0
        public void SaveScreenshot(string filename)
        {
            Color[] screenData = new Color[GraphicsDevice.PresentationParameters.BackBufferWidth * GraphicsDevice.PresentationParameters.BackBufferHeight];

            RenderTarget2D screenShot = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);

            GraphicsDevice.SetRenderTarget(screenShot);

            Draw(new GameTime());

            GraphicsDevice.SetRenderTarget(null);

            int index = 0;
            string name = string.Concat(filename, "_", index, ".jpg");
            while (File.Exists(name)) {
                index++;
                name = string.Concat(filename, "_", index, ".jpg");
            }

            using (FileStream stream = new FileStream(name, FileMode.CreateNew)) {
                screenShot.SaveAsJpeg(stream, screenShot.Width, screenShot.Height);
                screenShot.Dispose();
            }
        }
        /// <summary>
        /// Saves all the undoRedoRenderTargets to disk and the imageStateData
        /// </summary>
        /// <param name='imageStateData'>Image state data.</param>
        /// <param name='masterImageRenderTarget' Master image render target/>
        /// <param name='undoRedoRenderTargets'>Sequence of images representing the undo/redo chain</param>
        /// <param name='bottomMarginToCutOff'>Because the toolbox will always take up some space we will cut off the bottom section (toolbox height)
        /// when saving the master image so that there is no annoying white space at the bottom</param>
        public void SaveData(ImageStateData imageStateData, RenderTarget2D masterImageRenderTarget, RenderTarget2D[] undoRedoRenderTargets, int bottomMarginToCutOff)
        {
            this.SaveImageStateData(this.filenameResolver.MasterImageInfoFilename, imageStateData);

            int end = imageStateData.FirstSavePoint == 0 ? imageStateData.LastSavePoint : imageStateData.MaxUndoRedoCount - 1;

            for (int count = 0; count <= end; count++)
            {
                var renderTarget = undoRedoRenderTargets[count];

                // Save the render target to disk
                renderTarget.SaveAsPng(
                    this.filenameResolver.ImageSavePointFilename(count),
                    renderTarget.Width,
                    renderTarget.Height);

                // copy the working canvas recorder file into the master folder.
                var masterCanvasRecorderFile = this.filenameResolver.MasterCanvasRecorderFilename(count);

                if (File.Exists(masterCanvasRecorderFile))
                {
                    File.Delete(masterCanvasRecorderFile);
                }

                File.Move(this.filenameResolver.WorkingCanvasRecorderFilename(count), masterCanvasRecorderFile);
            }

            // Save the Master image as a JPG as it has no alpha channel - which is ideal for displaying on the home
            // home screen where we don't want the background image showing through
            masterImageRenderTarget.SaveAsJpeg(
                this.filenameResolver.MasterImageFilename,
                masterImageRenderTarget.Width,
                masterImageRenderTarget.Height - bottomMarginToCutOff);

            File.Delete(this.filenameResolver.WorkingImageInfoFilename);
        }