WICConvertBitmapSource 関数 (wincodec.h)

指定した IWICBitmapSource から目的のピクセル形式の IWICBitmapSource を取得します

構文

HRESULT WICConvertBitmapSource(
  [in]  REFWICPixelFormatGUID dstFormat,
  [in]  IWICBitmapSource      *pISrc,
  [out] IWICBitmapSource      **ppIDst
);

パラメーター

[in] dstFormat

型: REFWICPixelFormatGUID

変換するピクセル形式。

[in] pISrc

種類: IWICBitmapSource*

元のビットマップ。

[out] ppIDst

種類: IWICBitmapSource**

null で初期化された宛先ビットマップ ポインターへのポインター。

戻り値

型: HRESULT

この関数が成功すると、 S_OKが返されます。 そうでない場合は、HRESULT エラー コードを返します。

注釈

pISrc ビットマップが既に目的の形式である場合は、pISrc がコピー先ビットマップ ポインターにコピーされ、参照が追加されます。 ただし、目的の形式でない場合、 WICConvertBitmapSourcedstFormat 形式コンバーターをインスタンス化し、 pISrc を使用して初期化します。

次の例では、 IWICBitmapSourceGUID_WICPixelFormat128bppPRGBAFloat ピクセル形式に変換します。

   IWICImagingFactory *pFactory = NULL;
   IWICBitmapDecoder *pDecoder = NULL;
   IWICBitmapFrameDecode *pBitmapFrameDecode = NULL;
   IWICBitmapSource *pConverter = NULL;

   UINT uiFrameCount = 0;
   UINT uiWidth = 0, uiHeight = 0;
   WICPixelFormatGUID pixelFormat;    

   // Create the image factory.
   HRESULT hr = CoCreateInstance(CLSID_WICImagingFactory,
                    NULL,
                    CLSCTX_INPROC_SERVER,
                    IID_IWICImagingFactory,
                    (LPVOID*) &pFactory);

   // Create a decoder from the file.
   if (SUCCEEDED(hr))
   {
      hr = pFactory->CreateDecoderFromFilename(L"test.jpg",
                         NULL,
                         GENERIC_READ,
                         WICDecodeMetadataCacheOnDemand,
                         &pDecoder);
   }

   // Get the frame count.
   if (SUCCEEDED(hr))
   {
      hr = pDecoder->GetFrameCount(&uiFrameCount);
   }

   if (SUCCEEDED(hr) && (uiFrameCount > 0))
   {
      IWICBitmapSource *pSource = NULL;

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

      if (SUCCEEDED(hr))
      {
         pSource = pBitmapFrameDecode;
         pSource->AddRef();

         hr = pSource->GetSize(&uiWidth, &uiHeight);
      }

      if (SUCCEEDED(hr))
      {
         hr = pSource->GetPixelFormat(&pixelFormat);
      }

      if (SUCCEEDED(hr))
      {
         if (!IsEqualGUID(pixelFormat, GUID_WICPixelFormat128bppPRGBAFloat))
         {

            hr = WICConvertBitmapSource(GUID_WICPixelFormat128bppPRGBAFloat, pSource, &pConverter);

            if (SUCCEEDED(hr))
            {
               pSource->Release();     // the converter has a reference to the source
               pSource = NULL;         // so we don't need it anymore.
               pSource = pConverter;   // let's treat the 128bppPABGR converter as the source
            }
         }

         if (piConverter)
         {
            UINT cbStride = uiWidth * sizeof(float) * 4;
            UINT cbBufferSize = cbStride;

            float *pixels = new float[cbBufferSize / sizeof(float)];

            if (pixels)
            {                    
               WICRect rc;
               rc.X = 0;
               rc.Y = 0;
               rc.Width = uiWidth;
               rc.Height = 1;

               for (UINT i = 0; SUCCEEDED(hr) && i < uiHeight; i++)
               {
                  hr = pSource->CopyPixels(&rc,
                                    cbStride,
                                    cbBufferSize,
                                    reinterpret_cast<BYTE*>(pixels));

                  // Do something with the scanline here...

                  rc.Y++;
               }

               delete[] pixels;
            }
            else
            {
               hr = E_OUTOFMEMORY;
            }

            pConverter->Release();
         }
      }
   }

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

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

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

   return hr;

要件

要件
サポートされている最小のクライアント WINDOWS XP と SP2、Windows Vista [デスクトップ アプリ |UWP アプリ]
サポートされている最小のサーバー Windows Server 2008 [デスクトップ アプリ | UWP アプリ]
対象プラットフォーム Windows
ヘッダー wincodec.h
Library Windowscodecs.lib
[DLL] Windowscodecs.dll