将 .dds 转换为 .png:XNA 真的这么复杂吗?

发布于 2024-09-25 21:01:53 字数 1393 浏览 2 评论 0原文

我有一个 .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 call myTexture2D.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 a GraphicsDeviceManager... oh wait, I'm not going down that path again, no more Managers 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 this PresentationParameters thing well OK I'll just try new PresentationParameters());.
  • Well that threw an exception. They want... a DeviceWindowHandle in my PresentationParameters? 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

永不分离 2024-10-02 21:01:53

如果您有需要创建 XNA 图形设备的命令行应用程序,请使用 这个答案应该有一些帮助。

简而言之,您需要 WinForms 示例 中的一些类以避免创建图形设备服务等(特别是类 ServiceContainerGraphicsDeviceService)。

然后你可以这样做:

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");

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 and GraphicsDeviceService).

Then you can do this:

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");

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.

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.

记忆里有你的影子 2024-10-02 21:01:53

从我的想法来看(有一段时间没有使用 XNA):

  • 数据类型的转换不是 XNA 的常见场景。它希望内容管道对所有资产进行预处理。
  • XNA 经常需要图形设备,无窗口应用程序超出了 XNA 的范围。

在我看来,你在这项工作中使用了错误的工具,尽管我无法告诉除了 DevIL 之外的其他工具,你已经驳回了它。

From the top of my head (haven't used XNA for a while):

  • Conversion of datatypes is not a common scenario for XNA. It expects to get all assets preprocessed by the content pipeline.
  • XNA expects the graphics device quite often, windowless applications are out of XNAs scope.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文