title: Getting a Texture2D from a RenderTarget2D object in XNA 4.0
body: <p>Im just experimenting with pixel shader. I found a nice blur effect and now Im trying to create an effect of blurring an image over and over.</p>
  
  <p>HOW I want to do that: I want to render my image <em>hellokittyTexture</em> in a RenderTarget applying the blur effect, then replace <em>hellokittyTexture</em> with the result of that render and do it over and over again every Draw iteration:</p>
  
  <pre><code>protected override void Draw(GameTime gameTime)
      {
  
          GraphicsDevice.Clear(Color.CornflowerBlue);
  
  
          GraphicsDevice.SetRenderTarget(buffer1);
  
          // Begin the sprite batch, using our custom effect.
          spriteBatch.Begin(0, null, null, null, null, blur);
          spriteBatch.Draw(hellokittyTexture , Vector2.Zero, Color.White);
          spriteBatch.End();
          GraphicsDevice.SetRenderTarget(null);
  
          hellokittyTexture = (Texture2D) buffer1;
  
          // Draw the texture in the screen
          spriteBatch.Begin(0, null, null, null, null, null);
          spriteBatch.Draw(hellokittyTexture , Vector2.Zero, Color.White);
          spriteBatch.End();
  
          base.Draw(gameTime);
      }
  </code></pre>
  
  <p>But I get this error <em>"The render target must not be set on the device when it is used as a texture."</em> Because <code>hellokittyTexture = (Texture2D) buffer1;</code> is not copying the texture but the reference to the RenderTarget (basicly they are the same object after the asignation)</p>
  
  <p>Do you know a nice way to get the Texture inside the RenderTarget? or a more elegant way to do what Im trying? </p>