Jak pobrać ramki z obrazu
W tym temacie przedstawiono sposób dekodowania obrazu z wieloma ramkami i pobierania każdej ramki do przetwarzania.
Aby pobrać klatki obrazu
Utwórz IWICImagingFactory, aby utworzyć obiekty Windows Imaging Component (WIC).
// Create WIC factory hr = CoCreateInstance( CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_pIWICFactory) );
Użyj metody CreateDecoderFromFilename, aby utworzyć IWICBitmapDecoder z pliku obrazu.
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 );
Pobierz liczbę ramek na obrazach.
// Retrieve the frame count of the image. if (SUCCEEDED(hr)) { hr = pIDecoder->GetFrameCount(&nFrameCount); }
Przetwarzaj każdą ramkę, uzyskując IWICBitmapFrameDecode dla każdej ramki na obrazie.
// 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); }