![]() JPEG images will only have one frame and the loop below is not technically necessary but is included to demonstrate multi-frame usage for formats that support it.įor (UINT i=0 iGetFrame(i, &piFrameDecode) This copy includes size, resolution, and pixel format all of which are necessary to create a valid frame. The following code copies each frame of an image to a new frame of the encoder. piFileStream is then used to initialize the encoder, informing the encoder where to write the image bits when the encoding is complete. ![]() Hr = piEncoder->Initialize(piFileStream,WICBitmapEncoderNoCache) Ī WIC file stream piFileStream is created and initialized for writing to the image file "test2.jpg". Hr = piFactory->CreateEncoder(GUID_ContainerFormatJpeg, NULL, &piEncoder) Hr = piFileStream->InitializeFromFilename(L"test2.jpg", GENERIC_WRITE) Hr = piFactory->CreateStream(&piFileStream) IWICMetadataBlockReader *piBlockReader = NULL IWICMetadataBlockWriter *piBlockWriter = NULL The following code demonstrates the creation of the encoder you will use to encode the image you previously decoded. Part 2: Create and Initialize the Image Encoder Alternatively, you could use the other WICDecodeOptions value, WICDecodeMetadataCacheOnLoad, which caches the embedded image metadata as soon as the image is loaded. Using this option enables you to retain the stream to the metadata, which is required for performing fast metadata encoding and enables lossless decoding and encoding of JPEG images. This tells the decoder to cache the metadata when the metadata is needed, either by obtaining a query reader or by using the underlying metadata reader. The call to CreateDecoderFromFilename used the value WICDecodeMetadataCacheOnDemand from the WICDecodeOptions enumeration as the fourth parameter. WICDecodeMetadataCacheOnDemand, //For JPEG lossless decoding/encoding. Hr = piFactory->CreateDecoderFromFilename(L"test.jpg", NULL, GENERIC_READ, Hr = CoCreateInstance(CLSID_WICImagingFactory, ![]() HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED) The following code demonstrates how to create a WIC decoder for the image file test.jpg. Part 1: Decode an Imageīefore you can copy image data or metadata to a new image file, you must first create a decoder for the existing image that you want to re-encode. You should also be familiar with the WIC codec components as described in the Windows Imaging Component Overview. To understand this topic, you should be familiar with the Windows Imaging Component (WIC) metadata system as described in the WIC Metadata Overview. Part 2: Create and Initialize the Image Encoder.This topic contains the following sections. In addition, this example adds metadata to demonstrate a single-item expression used by a query writer. The following example demonstrates how to re-encode an image and its metadata to a new file of the same format.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |