WIC WINCODEC_ERR_BADHEADER only for JPEG images

若如初见. 提交于 2020-01-16 19:28:26

问题


I have a simple encoding/ decoding application using Windows Imaging Component API. The issue I'm having is that when I use either the JPEGXR or BMP formats, everything works fine. However, when I use the JPEG codec - the encoder works fine and I can visually verify the generated JPEG image, but when I try to decode that stream, I get a WINCODEC_ERR_BADHEADER (0x88982f61)

Here's the line that fails:

    hr = m_pFactory->CreateDecoderFromStream(
                                    pInputStream, 
                                    NULL,
                                    WICDecodeMetadataCacheOnDemand,
                                    &pDecoder);

Here pInputStream is an IStream created from a byte array (output of the encoder - a black box which outputs a byte vector).

Please help! This is driving me nuts!


回答1:


When passing stream as an argument, make sure to pre-seek it to proper initial position (esp. seek it back to the beginning if you just wrote data into it and expect further retrieval). APIs are typically not expected to seek, because this way they let you provide data in the middle of a bigger stream.



来源:https://stackoverflow.com/questions/12927623/wic-wincodec-err-badheader-only-for-jpeg-images

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!