Méthode IWICStream ::InitializeFromFilename (wincodec.h)

Initialise un flux à partir d’un fichier particulier.

Syntaxe

HRESULT InitializeFromFilename(
  [in] LPCWSTR wzFileName,
  [in] DWORD   dwDesiredAccess
);

Paramètres

[in] wzFileName

Type : LPCWSTR

Fichier utilisé pour initialiser le flux.

[in] dwDesiredAccess

Type : DWORD

Mode d’accès aux fichiers souhaité.

Valeur Signification
GENERIC_READ
Accès en lecture.
GENERIC_WRITE
Accès en écriture.

Valeur retournée

Type : HRESULT

Si cette méthode réussit, elle retourne S_OK. Sinon, elle retourne un code d’erreur HRESULT.

Remarques

Les méthodes d’interface IWICStream ne vous permettent pas de fournir une option de partage de fichiers. Pour créer un flux de fichiers partagé pour une image, utilisez la fonction SHCreateStreamOnFileEx . Ce flux peut ensuite être utilisé pour créer un IWICBitmapDecoder à l’aide de la méthode CreateDecoderFromStream .

Exemples

Cet exemple illustre l’utilisation de InitializeFromFilename pour créer un décodeur d’image.

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

    HRESULT hr = CoCreateInstance(
                    CLSID_WICImagingFactory,
                    NULL,
                    CLSCTX_INPROC_SERVER,
                    IID_PPV_ARGS(&pFactory));

    // Create the stream.
    if (SUCCEEDED(hr))
    {
        hr = pFactory->CreateStream(&pStream);
    }

    // Initialize the stream from a specific file.
    if (SUCCEEDED(hr))
    {
        hr = pStream->InitializeFromFilename(L"test.jpg", GENERIC_READ);
    }    

    // Create a JPEG decoder.
    // Since the stream is created from the JPEG file, an explicit JPEG decoder
    // can be created using the generic IWICImagingFactory::CreateDecoder method.
    // However, use IWICImagingFactory::CreateDecoderFromStream method to auto
    // detect the stream and instantiate the appropriate codec.  
    if (SUCCEEDED(hr))
    {        
        hr = pFactory->CreateDecoder(
                GUID_ContainerFormatJpeg,   // Explicitly create a JPEG decoder.
                NULL,                       // No preferred vendor.
                &pDecoder);                 // Pointer to the decoder.
    } 

    // Initialize the decoder
    if (SUCCEEDED(hr))
    {
        hr = pDecoder->Initialize(
                pStream,                            // The stream to use.
                WICDecodeMetadataCacheOnDemand);    // Decode metadata when needed.
    } 

    // Process image frame.
    if (SUCCEEDED(hr))
    {
        UINT cFrames = 0;

        hr = pDecoder->GetFrameCount(&cFrames);

        if (SUCCEEDED(hr) && (cFrames > 0))
        {
            UINT width = 0, height = 0;        
            IWICBitmapFrameDecode *pBitmapFrame = NULL;

            hr = pDecoder->GetFrame(0, &pBitmapFrame);

            if (SUCCEEDED(hr))
            {
                // Do something with the frame here.
            }

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

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

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

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

Configuration requise

Condition requise Valeur
Client minimal pris en charge Windows XP avec SP2, Windows Vista [applications de bureau | Applications UWP]
Serveur minimal pris en charge Windows Server 2008 [applications de bureau | applications UWP]
Plateforme cible Windows
En-tête wincodec.h
Bibliothèque Windowscodecs.lib
DLL Windowscodecs.dll