I wanted to test my application on the computer of a friend to check, if my work on runs on other peoples' machine. (Do I have included all libraries? Etc.)
However, my application crashes when I load *.dds textures. I use them in the 2D background of my scene. Here is the code I am using to load a DDS texture and convert them to Bitmaps:
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" are the data bytes of a DDS texture.
The thrown exception is
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)
Do you have any idea what's causing the problems?
The WIC-codec for DDS files has a number of important limitations. First, it's only included with Windows 8.1 or later. Second, it only supports BC1/BC2/BC3 (a.k.a. DXT1-DXT5) formats. See MSDN
Generally speaking, you are better off using a specialized DDS texture loader.
User contributions licensed under CC BY-SA 3.0