How to resize and save a Texture2D in XNA?

前端 未结 4 1448
不知归路
不知归路 2020-12-17 03:23

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 ac

4条回答
  •  青春惊慌失措
    2020-12-17 04:15

    Scaling images generally does not incur all that much overhead, plus, you wouldn't want to load different sizes of the same texture into memory as that would be a waste.

    Of course, you could be writing a Zune game, which means I'm probably off about the scaling there, but, anyway.

    I don't think you can save the scaled image directly from XNA, but, you could use WinForms Image class to load the image and then scale it to the dimensions in your level editor and save it back out to disk.

    If your texture isn't a BMP or PNG though, you may have to use the Texture2D.Save() command to convert it into a format you can use in the Image class.

    This thread might help you with using the Image class. http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/6fe3d353-0b09-440b-95c9-701efdc9e20a/

提交回复
热议问题