PathfindingTest.Map.MiniMap.GetScaledInstance C# (CSharp) Method

GetScaledInstance() public method

Gets a scaled instance of a texture.
public GetScaledInstance ( Microsoft.Xna.Framework.Graphics.Texture2D originalTexture, Vector2 targetSize ) : Microsoft.Xna.Framework.Graphics.Texture2D
originalTexture Microsoft.Xna.Framework.Graphics.Texture2D The original texture
targetSize Vector2 The vector target size.
return Microsoft.Xna.Framework.Graphics.Texture2D
        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;
        }

Same methods

MiniMap::GetScaledInstance ( Microsoft.Xna.Framework.Graphics.Texture2D originalTexture, float factor ) : Microsoft.Xna.Framework.Graphics.Texture2D