WICConvertBitmapSource-Funktion (wincodec.h)

Ruft eine IWICBitmapSource im gewünschten Pixelformat aus einer angegebenen IWICBitmapSource ab.

Syntax

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

Parameter

[in] dstFormat

Typ: REFWICPixelFormatGUID

Das Pixelformat, in das konvertiert werden soll.

[in] pISrc

Typ: IWICBitmapSource*

Die Quellbitmap.

[out] ppIDst

Typ: IWICBitmapSource**

Ein Zeiger auf den nullinitialisierten Zielbitbitbitzeiger.

Rückgabewert

Typ: HRESULT

Wenn diese Funktion erfolgreich ist, wird S_OK zurückgegeben. Andernfalls wird ein Fehlercode HRESULT zurückgegeben.

Hinweise

Wenn die pISrc-Bitmap bereits das gewünschte Format aufweist, wird pISrc in den Zielbitzeiger kopiert, und ein Verweis wird hinzugefügt. Wenn es sich jedoch nicht im gewünschten Format befindet, instanziiert WICConvertBitmapSource einen dstFormat-Formatkonverter und initialisiert ihn mit pISrc.

Beispiele

Im folgenden Beispiel wird eine IWICBitmapSource in ein GUID_WICPixelFormat128bppPRGBAFloat Pixelformat konvertiert.

   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;

Anforderungen

Anforderung Wert
Unterstützte Mindestversion (Client) Windows XP mit SP2, Windows Vista [Desktop-Apps | UWP-Apps]
Unterstützte Mindestversion (Server) Windows Server 2008 [Desktop-Apps | UWP-Apps]
Zielplattform Windows
Kopfzeile wincodec.h
Bibliothek Windowscodecs.lib
DLL Windowscodecs.dll