我想在朋友的计算机上测试我的应用程序,以检查我的工作是否在其他人的机器上运行。(我是否包括了所有库?等等(
但是,当我加载 *.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)
您知道是什么导致了问题吗?
DDS文件的WIC编解码器具有许多重要的限制。首先,它仅包含在 Windows 8.1 或更高版本中。其次,它仅支持 BC1/BC2/BC3(又名 DXT1-DXT5(格式。请参阅 MSDN
一般来说,您最好使用专门的DDS纹理加载器。