Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 178321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:12:39+00:00 2026-05-11T14:12:39+00:00

In a level editor I’ve made for my XNA game (editor is also in

  • 0

In a level editor I’ve made for my XNA game (editor is also in XNA) I’m allowing to scale Texture2D objects.

When the user tries to save the level, I’d like to actually resize the image file on disk so that it doesn’t require scaling in the game.

Is there an easy way to create an image file (PNG preferred) from a scaled Texture2D object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:12:40+00:00Added an answer on May 11, 2026 at 2:12 pm

    You can scale your textures by rendering to a render target at the size you want and then saving the render target texture.

    This simple example shows how you could do that. Ignore the setup of the GraphicsDevice, that’s just to make a small self-contained example. The interesting bit is creating the render target and drawing the scaled texture. You should reuse the render targets where you can (all images of the same size can reuse a render target).

    using System; using System.Runtime.InteropServices; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics;  class Program {     [DllImport('kernel32.dll', SetLastError = true)]     private static extern IntPtr GetConsoleWindow();      static void Main(string[] args)     {         string sourceImagePath = args[0];         string destinationImagePath = args[1];         int desiredWidth = int.Parse(args[2]);         int desiredHeight = int.Parse(args[3]);          GraphicsDevice graphicsDevice = new GraphicsDevice(             GraphicsAdapter.DefaultAdapter,             DeviceType.Hardware,             GetConsoleWindow(),             new PresentationParameters());         SpriteBatch batch = new SpriteBatch(graphicsDevice);          Texture2D sourceImage = Texture2D.FromFile(             graphicsDevice, sourceImagePath);          RenderTarget2D renderTarget = new RenderTarget2D(             graphicsDevice,              desiredWidth, desiredHeight, 1,              SurfaceFormat.Color);          Rectangle destinationRectangle = new Rectangle(             0, 0, desiredWidth, desiredHeight);          graphicsDevice.SetRenderTarget(0, renderTarget);          batch.Begin();         batch.Draw(sourceImage, destinationRectangle, Color.White);         batch.End();          graphicsDevice.SetRenderTarget(0, null);          Texture2D scaledImage = renderTarget.GetTexture();         scaledImage.Save(destinationImagePath, ImageFileFormat.Png);     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im doing a level editor for my game and i need to save the
I am currently working on a Level Editor for XNA which is built by
I want to create a somehow complex application: It is a game level editor.
I'd like to document what high-level (i.e. C++ not inline assembler ) functions or
I am looking after a level editor easy to use and configurable, so I
What level of CPU usage should be considered high for SQL Server? ie 80%
At what level of complexity is it mandatory to switch to an existing framework
I am an upper level Software Engineering student currently in a Data Structures and
On a more abstract level then a previous question , in my experience there
My comfort level with java is good , I wanted to teach my friend

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.