Share via


IWICStream::InitializeFromFilename 메서드(wincodec.h)

특정 파일에서 스트림을 초기화합니다.

구문

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

매개 변수

[in] wzFileName

형식: LPCWSTR

스트림을 초기화하는 데 사용되는 파일입니다.

[in] dwDesiredAccess

형식:DWORD

원하는 파일 액세스 모드입니다.

의미
GENERIC_READ
읽기 권한입니다.
GENERIC_WRITE
쓰기 권한입니다.

반환 값

형식: HRESULT

메서드가 성공하면 S_OK를 반환하고, 그러지 않으면 HRESULT 오류 코드를 반환합니다.

설명

IWICStream 인터페이스 메서드를 사용하면 파일 공유 옵션을 제공할 수 없습니다. 이미지에 대한 공유 파일 스트림을 만들려면 SHCreateStreamOnFileEx 함수를 사용합니다. 그런 다음 이 스트림을 사용하여 CreateDecoderFromStream 메서드를 사용하여 IWICBitmapDecoder를 만들 수 있습니다.

예제

이 예제에서는 InitializeFromFilename 을 사용하여 이미지 디코더를 만드는 방법을 보여 줍니다.

    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();
    }

요구 사항

요구 사항
지원되는 최소 클라이언트 WINDOWS XP SP2, Windows Vista [데스크톱 앱 | UWP 앱]
지원되는 최소 서버 Windows Server 2008 [데스크톱 앱 | UWP 앱]
대상 플랫폼 Windows
헤더 wincodec.h
라이브러리 Windowscodecs.lib
DLL Windowscodecs.dll