public Texture2D GetScaledInstance(Texture2D originalTexture, Vector2 targetSize)
{
RenderTargetBinding[] oldRenderTargets = Game1.GetInstance().GraphicsDevice.GetRenderTargets();
// Get the Texture with the screen drawn on it
// Create the Render Target to draw the scaled Texture to
RenderTarget2D newRenderTarget =
new RenderTarget2D(Game1.GetInstance().GraphicsDevice, (int)targetSize.X, (int)targetSize.Y);
// Set the given Graphics Device to draw to the new Render Target
Game1.GetInstance().GraphicsDevice.SetRenderTarget(newRenderTarget);
// Clear the scene
Game1.GetInstance().GraphicsDevice.Clear(Color.Transparent);
// Create the new SpriteBatch that will be used to scale the Texture
SpriteBatch cSpriteBatch = new SpriteBatch(Game1.GetInstance().GraphicsDevice);
// Draw the scaled Texture
cSpriteBatch.Begin();
cSpriteBatch.Draw(originalTexture, new Rectangle(0, 0, (int)targetSize.X, (int)targetSize.Y), Color.White);
cSpriteBatch.End();
// Restore the given Graphics Device's Render Target
Game1.GetInstance().GraphicsDevice.SetRenderTargets(oldRenderTargets);
Texture2D result = new Texture2D(Game1.GetInstance().GraphicsDevice, (int)targetSize.X, (int)targetSize.Y);
int[] data = new int[(int)targetSize.X * (int)targetSize.Y];
newRenderTarget.GetData(data);
result.SetData(data);
// Set the Texture To Return to the scaled Texture
return result;
}