How to scale a Texture2D instead of using SpriteBatch.Draw() to output it to the screen?

I want to scale a Texture2D and output the result to another Texture2D.For example , scale a 100X100 Texture2D object to 50X50 Texture2D object. But not use SpriteBatch.Draw() to output it to the screen.Thx

1 Like

Hello, you can do so with a RenderTarget2D.

  1. Create a 50x50 RenderTarget,
  2. use GraphicsDevice.SetRendertarget to send all your drawing to said rendertarget.
  3. SpriteBatch.Begiin,
  4. SpriteBatch.Draw (using as destination rectangle the created rendertarget .Bounds),
  5. SpriteBatch.End
  6. use GraphicsDevice.SetRendertarget(null) to reset all the drawing to the BackBuffer.
    In the end your rendertarget will have the scaled texture, with the quality of the scaling depending on your TextureSampling system.
2 Likes

not use SpriteBatch.

you can copy the texture data to a bitmap and resize that.

resize but cannot scale it

The easiest solution would be what Eversor suggested. It’s also favorable to do it all on the GPU so you avoid a pipeline stall of retrieving the data from VRAM. If that’s not possible in your situation, you may have to fetch the data with GetData, scale it with an algorithm, and put it into a new texture.

Maybe you said is right, I know that where I was wrong. thanks very much.

1 Like