Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to take a screenshot of the game when it's running, blur it and draw it on the screen. Could you help me with taking a screenshot and blurring it?

share|improve this question
The XNA post-processing sample is a good starting point for this. – Andrew Russell Jun 20 '13 at 14:56
up vote 9 down vote accepted

I have no source code to provide you, but I will point you in the correct direction. "Taking a Picture" is a simple task when rendering a game, you simply need to make a copy of the back buffer before it is swapped at the end of the render stage of your game loop.

If you then want to blur it, you will need to filter your image using one of many blur functions and a convolution matrix. This is typically done as a post processing step in engines, and it involves rendering a quad the size of the screen to a texture, while sampling the original back buffer image as an input.

A note here, this isn't a trivial thing unless you have sufficient experience with your rendering pipeline, and it would be far too much code to simply demonstrate the entire process.

Here is a link to the theory behind a Gaussian filter, and how it can be used to produce a blurred/smoothed image in the general context of computer vision.

share|improve this answer

I managed to do what I've wanted with this. Code:

bool prepareToPause, first, drawn, blurredReady;
Texture2D pausedScreenshot, blurredPauseScreenshot;
RenderTarget2D renderTarget;
enum GameState
const int BLUR_RADIUS = 7;
const float BLUR_AMOUNT = 2.0f;
GaussianBlur gaussianBlur;
int renderTargetWidth, renderTargetHeight;
RenderTarget2D renderTarget1, renderTarget2;

protected override void LoadContent()
        gaussianBlur = new GaussianBlur(this);
        gaussianBlur.ComputeKernel(BLUR_RADIUS, BLUR_AMOUNT);

        renderTarget = new RenderTarget2D(
        currentGameState = GameState.MainMenu;

private void InitRenderTargets()
            renderTargetWidth = pausedScreenshot.Width / 2;
            renderTargetHeight = pausedScreenshot.Height / 2;

            renderTarget1 = new RenderTarget2D(GraphicsDevice,
                renderTargetWidth, renderTargetHeight, false,

            renderTarget2 = new RenderTarget2D(GraphicsDevice,
                renderTargetWidth, renderTargetHeight, false,

            gaussianBlur.ComputeOffsets(renderTargetWidth, renderTargetHeight);

protected override void Draw(GameTime gameTime)
            if (prepareToPause && !first)
                drawn = true;
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

            if (currentGameState == GameState.Playing)
                if (mouseRectangle.Intersects(nextWaveRectangle) && mouseState.RightButton == ButtonState.Pressed)
                    prepareToPause = true;

            if (prepareToPause && !first && drawn)

                pausedScreenshot = renderTarget;
                currentGameState = GameState.Paused;

            if (!first && drawn && currentGameState == GameState.Paused)
                blurredPauseScreenshot = gaussianBlur.PerformGaussianBlur(pausedScreenshot, renderTarget1, renderTarget2, spriteBatch);
                blurRectangle = new Rectangle(0, 0, pausedScreenshot.Width, pausedScreenshot.Height);

                prepareToPause = false;
                blurredReady = true;
                first = true;

                spriteBatch.Draw(blurredPauseScreenshot, blurRectangle, Color.White);


I've probably made many errors but it's working and that's important for me at this point of my game development. Criticism and suggestions are welcome.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.