使用 D3DXSaveSurfaceToFile 保存的图像将在 Paint 中打开,而不是 Photoshop
我使用 D3DXSaveSurfaceToFile 将窗口化的 Direct3D 9 曲面保存为 PNG、BMP 和 JPG 文件。 D3DXSaveSurfaceToFile 调用没有返回任何错误,并且所有文件都可以在 Windows 照片查看器和画图器中正常打开。但它们无法在 Paint Shop Pro 或 Photoshop 等高端图像编辑程序中打开。这些程序的错误消息基本上表明文件已损坏。如果我在“画图”中打开文件,然后将它们保存为具有不同文件名的相同文件格式,那么它们将在其他程序中正常打开。
这让我相信 D3DXSaveSurfaceToFile 正在写出这些文件格式的非标准版本。有什么方法可以让这个函数写出可以在 Photoshop 等程序中打开的文件,而无需在 Paint 中重新保存文件的中间步骤吗?或者我应该使用另一个函数来更好地将 Direct3D 曲面保存到图像中?
I'm using D3DXSaveSurfaceToFile to save windowed Direct3D 9 surfaces to PNG, BMP and JPG files. There are no errors returned from the D3DXSaveSurfaceToFile call and all files open fine in Windows Photo Viewer and Paint. But they will not open in a higher end image editing program such as Paint Shop Pro or Photoshop. The error messages from these programs basically say that the file is corrupted. If I open the files in Paint and then save them in the same file format with a different file name, then they'll open fine in the other programs.
This leads me to believe that D3DXSaveSurfaceToFile is writing out non-standard versions of these file formats. Is there some way I can get this function to write out files that can be opened in programs like Photoshop without the intermediate step of resaving the files in Paint? Or is there another function I should be using that does a better job of saving a Direct3D surfaces to an image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在元查看器中查看图像中的文件。它告诉你什么?
Take a look at the file in a image meta viewer. What does it tell you?
不幸的是,D3DXSaveSurfaceToFile() 不是最稳定的(它也非常慢)。就我个人而言,我会执行类似以下代码的操作。它甚至可以在抗锯齿显示器上工作,通过进行离屏渲染来获取屏幕截图,然后将其放入缓冲区。它还仅支持最常见的像素格式。对于其中的任何错误,我深表歉意,将其从我曾经使用过的应用程序中删除。
然后,您可以在您的代码中,也可能在另一个线程中,使用各种不同的代码将所述“位图”转换为您喜欢的任何内容。
Unfortunately D3DXSaveSurfaceToFile() isn't the most stable (it's also exceptionally slow). Personally I do something like the below code. It works even on Anti-aliased displays by doing an offscreen render to take the screenshot then getting it into a buffer. It also supports only the most common of the pixel formats. Sorry for any errors in it, pulled it out of an app I used to work on.
You can then, in your code and probably in another thread, then convert said 'bitmap' to anything you like using a variety of different code.
事实证明,这是我的代码中的错误和 Paint 在读取文件时比 Photoshop 更宽容的结合。我的代码中的错误导致文件以错误的扩展名保存(即 Image.bmp 实际上是使用 D3DXIFF_JPG 保存的)。当打开包含 JPG 图像但具有 BMP 扩展名的文件时,Photoshop 只是失败了该文件。我猜画图可以工作,因为它忽略了文件扩展名,只是解码了文件内容。
查看 图像元中的文件查看器帮助我看到了问题。
Turns out that it was a combination of a bug in my code and Paint being more forgiving than Photoshop when it comes to reading files. The bug in my code caused the files to be saved with the wrong extension (i.e. Image.bmp was actually saved using D3DXIFF_JPG). When opening a file that contained a JPG image, but had a BMP extension, Photoshop just failed the file. I guess Paint worked since it ignored the file extension and just decoded the file contents.
Looking at a file in an image meta viewer helped me to see the problem.