Come recuperare i fotogrammi da un'immagine
Questo argomento illustra come decodificare un'immagine a più fotogrammi e recuperare ogni frame per l'elaborazione.
Per recuperare i fotogrammi di un'immagine
Creare un oggetto IWICImagingFactory per creare oggetti Windows Imaging Component (WIC).
// Create WIC factory hr = CoCreateInstance( CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_pIWICFactory) );
Utilizzare il metodo CreateDecoderFromFilename per creare un file di immagine 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 );
Recuperare il numero di fotogrammi nelle immagini.
// Retrieve the frame count of the image. if (SUCCEEDED(hr)) { hr = pIDecoder->GetFrameCount(&nFrameCount); }
Elaborare ogni frame ottenendo un IWICBitmapFrameDecode per ogni frame nell'immagine.
// 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); }
Vedere anche