将 .dds 转换为 .png:XNA 真的这么复杂吗?
我有一个 .dds 文件,我想要一个 .png 文件。虽然我已经发现< a href="http://www.mastropaolo.com/devildotnet/" rel="nofollow noreferrer">DevIL.NET 库,其中一个静态类的 API 设计不并行,所以我希望寻找另一种方法。这让我找到了 XNA。
但是,这就是我对这个想法的了解……
- 好吧,看起来我想要这个
Texture2D
类;然后我可以调用myTexture2D.SaveAsPng
。 - 但如何从 .dds 文件中获取其中之一呢?好吧,文档似乎表明我想使用
myContentManager.Load
。 - 哦,糟糕,不是这样,那是某种游戏内容管理系统。好吧,我的搜索似乎发现了很多
myTexture2D.LoadFile
的用途;我会去做的。 - 呃,我是否缺少程序集参考或其他东西?哦不,我明白了,他们在 3.1 和 4.0 之间删除了该方法,太棒了。好吧,这有点烦人,但是 myTexture2D.LoadStream 并不是真正的问题。
- 等等,现在这是什么?它想要一个 GraphicsDevice 吗?嗯,看起来人们通常通过
GraphicsDeviceManager
获得其中之一...哦等等,我不会再走这条路了,不再有Manager
对我来说。 - 我想我应该手动实例化这个东西。好吧,这并不太难...
var myGraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef,
(呃哦,这是什么PresentationParameters
好吧,我会尝试newPresentationParameters());
。 - 好吧,他们想要...在我的
PresentationParameters
中使用DeviceWindowHandle
? strong>但是我正在运行一个控制台应用程序!!
所以我真的希望有一种更简单的方法来做到这一点;也许我可以使用某种默认的GraphicsDevice
。创建整个窗口只是为了将 .dds 转换为 .png 是相当愚蠢的,
我想欢迎针对我的转换问题提出替代建议,尽管总体上了解如何从非 XNA 代码使用 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...
- 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!!
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有需要创建 XNA 图形设备的命令行应用程序,请使用 这个答案应该有一些帮助。
简而言之,您需要 WinForms 示例 中的一些类以避免创建图形设备服务等(特别是类
ServiceContainer
和GraphicsDeviceService
)。然后你可以这样做:
Tada - 现在你有了一个可以用来加载内容的工作
ContentManager
。我相信您也应该能够从GraphicsDeviceService
获取实际的GraphicsDevice
。您创建的表单永远不会显示。请记住在项目中引用
System.Windows.Forms.dll
。免责声明:这是为 XNA 3.1 编写的。我还没有在 4.0 中测试过它,但我怀疑它只需很少的修改或无需修改就可以工作。
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.
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
andGraphicsDeviceService
).Then you can do this:
Tada - now you have a working
ContentManager
that you can use to load stuff. I believe you should be able to get the actualGraphicsDevice
from theGraphicsDeviceService
, too.The form you create is never displayed. Remember to reference
System.Windows.Forms.dll
in your project.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.
从我的想法来看(有一段时间没有使用 XNA):
在我看来,你在这项工作中使用了错误的工具,尽管我无法告诉除了 DevIL 之外的其他工具,你已经驳回了它。
From the top of my head (haven't used XNA for a while):
It seems to me that you are using the wrong tool for the job, although I couldn't tell another one except DevIL, which you already dismissed.