转换的.dds为.png格式:是真的XNA这令人费解? [英] Converting .dds to .png: is XNA really this convoluted?
问题描述
我有一个文件的.dds,我想.png文件。虽然我已经发现了中的< A HREF =http://www.mastropaolo.com/devildotnet/相对=nofollow> DevIL.NET库,该API的设计有一个静态类不进行并行化,所以我希望能找到另一种方法。这使我XNA。
I have a .dds file and I want a .png file. Although I already found out about the DevIL.NET library, the API design there of one static class does not parallelize, so I am hoping to find another method. This led me to XNA.
不过,这里是多远我有这个想法了......
But, here's how far I got with that idea...
- 确定,它看起来像我希望这个
的Texture2D
类;那么我可以叫myTexture2D.SaveAsPng
。 - 可是我怎么得到那些从我的.dds文件的一个?那么文档似乎表明我想用
myContentManager.Load<的Texture2D方式>
- 呵呵废话,那是不是,这是某种形式的游戏内容管理系统。好了,我的搜索似乎已经变成了很多
myTexture2D.LoadFile
的用途;我会去试试。 - 呃我缺少的程序集引用的东西?哦,不,我明白了,他们去除了3.1和4.0,真棒之间的方法。好了,好了,这是一个有点讨厌,但
myTexture2D.LoadStream
不是一个真正的问题。 - 等待什么,现在是这样?它想要一个
的GraphicsDevice
?嗯,它看起来像人们通常得到通过那些之一的GraphicsDeviceManager
...哦,等等,我再也不走这路,没有更多的经理
给我的。 - 我想我应该手动实例化这个事情。确定以及这是不是太难...
VAR myGraphicsDevice =新的GraphicsDevice(GraphicsAdapter.DefaultAdapter,GraphicsProfile.HiDef,
(嗯哦,这是什么PresentationParameters
的事情以及确定我只是尝试新PresentationParameters());
- 嘛抛出一个例外。他们想要一个...
DeviceWindowHandle
在我的PresentationParameters
?但是我正在运行控制台APP!
- OK, it looks like I want this
Texture2D
class; then I can callmyTexture2D.SaveAsPng
. - But how do I get one of those from my .dds file? Well the documentation seems to indicate I want to use
myContentManager.Load<Texture2D>
. - Oh crap, that wasn't it, that's some kind of game content management system. Well, my searching seems to have turned up a lot of uses of
myTexture2D.LoadFile
; I'll go for that. - Uh am I missing an assembly reference or something? Oh no, I get it, they removed that method between 3.1 and 4.0, awesome. OK, well, it's a bit more annoying, but
myTexture2D.LoadStream
isn't really a problem. - Wait what's this now? It wants a
GraphicsDevice
? Hmm it looks like one usually gets one of those via aGraphicsDeviceManager
... oh wait, I'm not going down that path again, no moreManager
s for me. - I guess I'm supposed to instantiate this thing manually. OK well this isn't too hard...
var myGraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef,
(uh oh what is thisPresentationParameters
thing well OK I'll just trynew PresentationParameters());
. - Well that threw an exception. They want... a
DeviceWindowHandle
in myPresentationParameters
? BUT I'M RUNNING A CONSOLE APP!!
所以我真的很希望有一个这样做的少令人费解的方式,也许某种违约的GraphicsDevice
我可以使用,感觉非常愚蠢创建一个整个窗口刚刚转换的.dds为.png格式。
So I'm really hoping there's a less convoluted way of doing this; perhaps some kind of default GraphicsDevice
I could use. It feels pretty silly to create a whole window just to convert .dds to .png.
另类的建议,我想,虽然它很可能是值得理解如何使用在一般的非XNA代码XNA。
Alternative suggestions for my conversion problem welcome, I guess, although it would probably be worthwhile to understand how to use XNA from non-XNA code in general.
推荐答案
如果您有需要创建一个XNA图形设备,在这个答案应该有些帮助。
If you have a command line app that needs to create an XNA graphics device, the code in this answer should be of some assistance.
在简单地说,你需要一些从的WinForms样品类,以避免浪费时间创建一个图形设备服务等方面(尤其是类的ServiceContainer
和 GraphicsDeviceService
)。
In a nutshell, you need some of the classes from the WinForms sample to avoid having to mess around creating a graphics device services and so on (specifically the classes ServiceContainer
and GraphicsDeviceService
).
然后,你可以这样做:
Form form = new Form(); // Dummy form for creating a graphics device
GraphicsDeviceService gds = GraphicsDeviceService.AddRef(form.Handle,
form.ClientSize.Width, form.ClientSize.Height);
ServiceContainer services = new ServiceContainer();
services.AddService<IGraphicsDeviceService>(gds);
content = new ContentManager(services, "Content");
田田 - 现在你有一个工作 ContentManager
你可以用它来装载什么东西。我相信你应该能够得到实际的的GraphicsDevice
从 GraphicsDeviceService
了。
Tada - now you have a working ContentManager
that you can use to load stuff. I believe you should be able to get the actual GraphicsDevice
from the GraphicsDeviceService
, too.
永远不会显示您所创建的窗体。记住引用 System.Windows.Forms.dll中
在您的项目
The form you create is never displayed. Remember to reference System.Windows.Forms.dll
in your project.
免责声明:本是为XNA 3.1编写。我还没有在4.0测试过,但我怀疑它会很少或根本没有修改工作。
Disclaimer: This was written for XNA 3.1. I haven't tested it in 4.0, but I suspect it will work with little or no modification.
这篇关于转换的.dds为.png格式:是真的XNA这令人费解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!