Share via


イメージからフレームを取得する方法

このトピックでは、マルチフレーム イメージをデコードし、処理のために各フレームを取得する方法について説明します。

イメージのフレームを取得するには

  1. IWICImagingFactory を作成して、Windows イメージング コンポーネント (WIC) オブジェクトを作成します。

    // Create WIC factory
    hr = CoCreateInstance(
        CLSID_WICImagingFactory,
        NULL,
        CLSCTX_INPROC_SERVER,
        IID_PPV_ARGS(&m_pIWICFactory)
        );
    
  2. CreateDecoderFromFilename メソッドを使用して、イメージ ファイルから IWICBitmapDecoder を作成します。

    HRESULT hr = S_OK;
    
    IWICBitmapDecoder *pIDecoder = NULL;
    IWICBitmapFrameDecode *pIDecoderFrame  = NULL;
    UINT nFrameCount = 0;
    UINT uiWidth, uiHeight;
    
    // Create decoder for an image.
    hr = m_pIWICFactory->CreateDecoderFromFilename(
       L"creek.tiff",                  // Image to be decoded
       NULL,                           // Do not prefer a particular vendor
       GENERIC_READ,                   // Desired read access to the file
       WICDecodeMetadataCacheOnDemand, // Cache metadata when needed
       &pIDecoder                      // Pointer to the decoder
       );
    
  3. イメージ内のフレーム数を取得します。

    // Retrieve the frame count of the image.
    if (SUCCEEDED(hr))
    {
       hr = pIDecoder->GetFrameCount(&nFrameCount);
    }
    
  4. 各フレームを処理するには、イメージ内の各フレームの IWICBitmapFrameDecode を取得します。

    // Process each frame in the image.
    for (UINT i=0; i < nFrameCount; i++)
    {
       // Retrieve the next bitmap frame.
       if (SUCCEEDED(hr))
       {
          hr = pIDecoder->GetFrame(i, &pIDecoderFrame);
       }
    
       // Retrieve the size of the bitmap frame.
       if (SUCCEEDED(hr))
       {
          hr = pIDecoderFrame->GetSize(&uiWidth, &uiHeight);
       }
    
       // Additional frame processing.
       // ...
    
       SafeRelease(&pIDecoderFrame);
    }
    

参照

プログラミング ガイド

参照

サンプル