Come creare un decodificatore usando un nome file immagine
In questo argomento viene descritto come creare un decodificatore bitmap usando un nome file di immagine.
Per creare un decodificatore bitmap usando un nome file di 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; hr = m_pIWICFactory->CreateDecoderFromFilename( L"turtle.jpg", // 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 );
Ottenere il primo IWICBitmapFrameDecode dell'immagine.
// Retrieve the first bitmap frame. if (SUCCEEDED(hr)) { hr = pIDecoder->GetFrame(0, &pIDecoderFrame); }
Il formato di file JPEG supporta solo un singolo frame. Poiché il file in questo esempio è un file JPEG, viene usato il primo frame (
0
). Per i formati di immagine con più fotogrammi, vedere Come recuperare i fotogrammi di un'immagine per accedere a ogni frame dell'immagine.Elaborare la cornice dell'immagine. Per altre informazioni sugli oggetti IWICBitmapSource , vedere Panoramica delle origini bitmap.
Vedere anche