Implementing IWICMetadataBlockWriter
IWICMetadataBlockWriter
The frame-level encoding class implements this interface to expose all the metadata blocks and request the appropriate metadata writer for each block. If your image format supports global metadata, outside of any individual frame, you should also implement this interface on the container-level encoder class. For a more detailed discussion of metadata handlers, refer to the section on the IWICMetadataBlockReader in the section on Implementing a WIC-Enabled Decoder.
interface IWICMetadataBlockWriter : IWICMetadataBlockReader
{
// All methods required
HRESULT InitializeFromBlockReader ( IWICMetadataBlockReader *pIMDBlockReader );
HRESULT GetWriterByIndex ( UINT nIndex, IWICMetadataWriter **ppIMetadataWriter );
HRESULT AddWriter (IWICMetadataWriter *pIMetadataWriter );
HRESULT SetWriterByIndex ( UINT nIndex, IWICMetadataWriter *pIMetadataWriter );
HRESULT RemoveWriterByIndex ( UINT nIndex );
}
InitializeFromBlockReader
InitializeFromBlockReader uses an IWICMetadataBlockReader to initialize the block writer. You can get the IWICMetadataBlockReader from the decoder that decoded the image.
UINT blockCount = 0;
IWICMetadataReader* pMetadataReader = NULL;
IWICMetadataWriter** ppMetadataWriter = NULL;
HRESULT hr;
hr = m_pBlockReader->GetCount(&blockCount);
ppMetadataWriter = IWICMetadataWriter*[blockCount];
for (UINT x=0; x < blockCount; x++)
{
hr = m_pBlockReader->GetReaderByIndex(&pMetadataReader);
hr = m_pComponentFactory->CreateMetadataWriterFromReader(
pMetadataReader, NULL, &ppMetadataWriter[x]);
}
Because initializing the IWICMetadataBlockWriter with an IWICMetadataBlockReader instantiates a metadata writer for each metadata reader exposed by the IWICMetadataBlockReader object, the application doesn’t have to explicitly request a writer for each block of metadata.
GetWriterByIndex
GetWriterByIndex returns the IWICMetadataWriter object for the nth metadata block, where n is the value passed in the nIndex parameter. If there is no metadata writer registered that can handle the type of metadata in the nth block, the component factory will return the Unknown Metadata Handler, which will treat the block of metadata as a binary large object (BLOB). It will serialize it out as a bit stream without attempting to parse it.
AddWriter
AddWriter allows a caller to add a new metadata writer. This is required if an application wants to add metadata of a different format than any of the existing metadata blocks. For example, an application may want to add some XMP metadata. If there is no existing XMP metadata block, the application must instantiate an XMP metadata writer and use the AddWriter method to include it in the collection of metadata writers.
SetWriterByIndex
SetWriterByIndex is used to add a metadata writer at a specific index in the collection. If a metadata writer is currently exists at that index, the new one should replace it.
RemoveWriterByIndex
RemoveWriterByIndex is used to remove a metadata writer from the collection.
Related topics
-
Conceptual