您现在的位置: IT专家网 > WinSystem子站 > 技巧
编写支持WIC的CODEC 并对图像格式支持
作者: Peggi Goodwin , 出处:微软, 责任编辑: 韩博颖,
2008-05-23 10:06
Vista Explorer、照片库和 Image Viewer 都基于 WIC 而构建,因此一旦在 Vista 系统中安装支持 WIC 的 CODEC,Vista 就会为相关图像格式提供与该平台所包含的标准图像格式同样级别的支持。
选择某个解码器来解码特定的图像后,应用程序会调用 Initialize。图像流被传递给解码器,调用方也可以指定缓存选项来处理文件中的元数据。
| enum WICDecodeOptions { WICDecodeMetadataCacheOnDemand, WICDecodeMetadataCacheOnLoad } |
GetContainerFormat 是所要实现的一个简单方法。它只针对解码器为其实例化的图像返回图像格式的 GUID。此方法也在 IWICMetadataBlockReader 和 IWICBitmapEncoder 上实现。
GetDecoderInfo 返回一个 IWICBitmapDecoderInfo 对象。要获得 IWICBitmapDecoderInfo 对象,只需将解码器的 GUID 传递给 IWICComponentFactory 上的 CreateComponentInfo 方法,然后请求其中的 IWICDecoderInfo 接口即可,如下所示。
| IWICComponentInfo* piComponentInfo = NULL; HRESULT hr; hr = m_piComponentFactory->CreateComponentInfo(CLSID_This, &piComponentInfo); hr = piComponentInfo->QueryInterface(IID_IWICBitmapDecoderInfo, (void**)ppIDecoderInfo); |
GetFrame 很可能是 IWICBitmapDecoder 接口上最重要的方法,因为帧中包含实际的图像位,而且该方法返回的帧解码器对象是对所请求图像进行实际解码的对象。它是在编写解码器时需要实现的另一个对象。有关此接口的更多信息,请参阅下面的 IWICBitmapFrameDecode。
GetPreview 返回图像预览。有关预览的详细讨论,请参阅 IWICBitmapEncoder 接口上的 SetPreview 方法。
如果您的图像格式包含内嵌 JPEG 预览,则不必编写 JPEG 解码器来将其解码。实际上,我们强烈建议您不要那么做。而是应委托 WIC 平台附带的 JPEG 解码器来将预览和缩略图解码。为此,应找到流中预览图像数据的起点并调用图像工厂的 CreateDecoderFromStream 方法。
| IWICBitmapDecoder* piPreviewDecoder = NULL; IWICBitmapFrameDecode* piPreviewFrame = NULL; IWICBitmapSource* piPreview = NULL; HRESULT hr; hr = m_piImagingFactory->CreateDecoderFromStream(m_piStream, NULL, WICDecodeMetadataCacheOnDemand, &piPreviewDecoder); hr = piPreviewDecoder->GetFrame(0, piPreviewFrame); hr = piPreviewFrame->QueryInterface(IID_IWICBitmapSource, (void**)&piPreview); IWICBitmapCodecProgressNotification |
- 本文关键词:

