Export (0) Print
Expand All

IWICBitmapDecoderInfo interface

Exposes methods that provide information about a decoder.

Members

The IWICBitmapDecoderInfo interface inherits from IWICBitmapCodecInfo. IWICBitmapDecoderInfo also has these types of members:

Methods

The IWICBitmapDecoderInfo interface has these methods.

MethodDescription
CreateInstance

Creates a new IWICBitmapDecoder instance.

GetPatterns

Retrieves the file pattern signatures supported by the decoder.

MatchesPattern

Retrieves a value that indicates whether the codec recognizes the pattern within a specified stream.

 

Examples

The following example enumerates all avaliable WIC components and uses MatchesPattern to determine if the component matches the stream. If so, an instance of the IWICBitmapDecoder that matches the pattern is instantiated using CreateInstance to retrieve the WICBitmapDecoderCapabilities.


    IWICImagingFactory *pFactory = NULL;
    IWICStream *pStream = NULL;
    IEnumUnknown *pEnumerator = NULL;
    IWICBitmapDecoder *pDecoder = NULL;

    HRESULT hr = CoCreateInstance(
                    CLSID_WICImagingFactory, 
                    NULL,
                    CLSCTX_INPROC_SERVER,
                    IID_IWICImagingFactory,
                    (LPVOID*) &pFactory);

    if (SUCCEEDED(hr))
    {
        hr = pFactory->CreateStream(&pStream);
    }

    if (SUCCEEDED(hr))
    {
        hr = pStream->InitializeFromFilename(L"test.jpg", GENERIC_READ);
    }

    if (SUCCEEDED(hr))
    {
        hr = pFactory->CreateComponentEnumerator(
                           WICDecoder,
                           WICComponentEnumerateDefault,
                           &pEnumerator);
    }

    if (SUCCEEDED(hr))
    {
        IUnknown *pUnknown = NULL;
        IWICBitmapDecoderInfo *pDecoderInfo = NULL;
        ULONG actual = 0;
        ULONG ulHighestWeight = 0;
        CLSID clsid = { 0 };

        while (SUCCEEDED(hr) && SUCCEEDED(pEnumerator->Next(1, &pUnknown, &actual)) && (actual > 0))
        {
            BOOL fPatternMatch = FALSE;

            hr = pUnknown->QueryInterface(
                               IID_IWICBitmapDecoderInfo,
                               reinterpret_cast<void**>(&pDecoderInfo));
            pUnknown->Release();
            pUnknown = NULL;

            if (SUCCEEDED(hr))
            {
                hr = pDecoderInfo->MatchesPattern(pStream, &fPatternMatch);
            }

            if (SUCCEEDED(hr) && fPatternMatch)
            {
                hr = pDecoderInfo->CreateInstance(&pDecoder);

                if (SUCCEEDED(hr))
                {
                    ULONG ulWeight = 0;
                    DWORD capabilities;
                    hr = pDecoder->QueryCapability(pStream, &capabilities);

                    if (SUCCEEDED(hr))
                    {
                        // We're going to weight a decoder whose encoder created the file the highest,
                        // followed (from higher to lower importance) by decoders that can extract an image,
                        // thumbnail, and metadata. Keep in mind that an app can use a different heuristic
                        // here, depending on the type of information that it needs from the decoder. If it
                        // only needs metadata, it can simply grab the first decoder that can parse metadata.
                        ulWeight = ((capabilities & WICBitmapDecoderCapabilitySameEncoder)          != 0) * 5 +
                                   ((capabilities & WICBitmapDecoderCapabilityCanDecodeAllImages)   != 0) * 4 +
                                   ((capabilities & WICBitmapDecoderCapabilityCanDecodeSomeImages)  != 0) * 3 +
                                   ((capabilities & WICBitmapDecoderCapabilityCanDecodeThumbnail)   != 0) * 2 +
                                   ((capabilities & WICBitmapDecoderCapabilityCanEnumerateMetadata) != 0);

                        if (ulWeight > ulHighestWeight)
                        {
                            hr = pDecoderInfo->GetCLSID(&clsid);

                            if (SUCCEEDED(hr))
                            {
                                ulHighestWeight = ulWeight;
                            }
                        }
                    }

                    pDecoder->Release();
                    pDecoder = NULL;
                }
            }

            pDecoderInfo->Release();
            pDecoderInfo = NULL;
        }

        pEnumerator->Release();
        pEnumerator = NULL;
    }

    if (pStream)
    {
        pStream->Release();
    }

    if (pFactory)
    {
        pFactory->Release();
    }

    return hr;

Requirements

Minimum supported client

Windows XP with SP2, Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 [desktop apps | Windows Store apps]

Header

Wincodec.h

IDL

Wincodec.idl

Library

Windowscodecs.lib

DLL

Windowscodecs.dll

 

 

Community Additions

ADD
Show:
© 2014 Microsoft