处理DDS文件时BitmapDecoder崩溃

时间:2017-05-10 15:30:18

标签: bitmap textures bitmapfactory sharpdx wic

如果我的工作在其他人的机器上运行,我想在朋友的计算机上测试我的应用程序。 (我是否包含了所有库?等等。)

但是,当我加载* .dds纹理时,我的应用程序崩溃了。我在场景的2D背景中使用它们。这是我用来加载DDS纹理并将它们转换为位图的代码:

using (SharpDX.WIC.BitmapDecoder bitmapDecoder = new SharpDX.WIC.BitmapDecoder(ImagingFactory, new MemoryStream(iconInfo.Data, false), SharpDX.WIC.DecodeOptions.CacheOnDemand))
{
    using (SharpDX.WIC.FormatConverter formatConverter = new SharpDX.WIC.FormatConverter(ImagingFactory))
    {
        formatConverter.Initialize(bitmapDecoder.GetFrame(0), SharpDX.WIC.PixelFormat.Format32bppPRGBA, SharpDX.WIC.BitmapDitherType.None, null, 0.0, SharpDX.WIC.BitmapPaletteType.Custom);

        SharpDX.DataStream dataStream = new SharpDX.DataStream(formatConverter.Size.Height * formatConverter.Size.Width * 4, true, true);
        formatConverter.CopyPixels(formatConverter.Size.Width * 4, dataStream);

        _icons.Add(iconInfo.Name, new SharpDX.Direct2D1.Bitmap(renderTarget, new SharpDX.Size2(formatConverter.Size.Width, formatConverter.Size.Height), dataStream,
            formatConverter.Size.Width * 4, bitmapProperties));
    }
}

“iconInfo.Data”是DDS纹理的数据字节。

抛出的异常是

SharpDX.SharpDXException: HRESULT: [0x88982F50], Module: [SharpDX.WIC], ApiCode: [WINCODEC_ERR_COMPONENTNOTFOUND/Componentnotfound], Message: Unknown
   at SharpDX.Result.CheckError()
   at SharpDX.WIC.ImagingFactory.CreateDecoderFromStream_(IntPtr streamRef, Nullable`1 guidVendorRef, DecodeOptions metadataOptions, BitmapDecoder decoderOut)
   at SharpDX.WIC.BitmapDecoder..ctor(ImagingFactory factory, Stream streamRef, DecodeOptions metadataOptions)

你知道造成这些问题的原因是什么吗?

1 个答案:

答案 0 :(得分:0)

DDS文件的WIC-codec有许多重要的限制。首先,它仅包含在Windows 8.1或更高版本中。其次,它仅支持BC1 / BC2 / BC3(a.k.a.DXT1-DXT5)格式。见MSDN

一般来说,最好使用专门的DDS纹理加载器。