LEAD Technologies, Inc

LEAD Bitmap Encoder Property Bag: XPS Specific Options

Provides additional options for the LEAD XPS Bitmap Encoder. XPS stands for the XML Paper Specification.

Property Bag Items

LEAD XPS Encoder Options
Property Name VARTYPE Default Value Applicable LEAD Encoders Description
XResolution VT_I4 96 XPS Horizontal display resolution in dots per inch.
YResolution VT_I4 96 XPS Vertical display resolution in dots per inch.

Example

            // This example shows how to save an XPS file with options using the property bag
            // Then the file is saved with the following options:
            // * XResolution: 300
            // * YResolution: 300
            // Refer to the Example Requirements for help in running this sample
            HRESULT IWICLeadBitmapEncoder_PropertyBag_Xps(HWND hWnd, WCHAR *pszOut)
            {
               HRESULT hr = S_OK;
               IWICImagingFactory *piImagingFactory = NULL;
               IWICBitmapEncoder *piBitmapEncoder = NULL;
               IWICBitmapFrameEncode *piBitmapFrameEncode = NULL;
               IWICStream *piStream = NULL;
               IPropertyBag2 *piPropertyBag = NULL;
               CString csExampleName;
               GUID guidContainerFormat = GUID_ContainerFormatLeadXps;
               WICPixelFormatGUID guidPixelFormat = GUID_WICPixelFormat24bppBGR;
            
               csExampleName.Format(L"IWICLeadBitmapEncoder_PropertyBag_Xps\nThis example creates an Xps file (%s) with XResolution 300, and YResolution 300", pszOut);
            
               // Create a LEAD Jpeg Bitmap Encoder
               IFS(CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*) &piImagingFactory));
            
               IFS(piImagingFactory->CreateStream(&piStream));
               IFS(piStream->InitializeFromFilename(pszOut, GENERIC_WRITE));
               IFS(piImagingFactory->CreateEncoder(guidContainerFormat, NULL, &piBitmapEncoder));
               IFS(piBitmapEncoder->Initialize(piStream, WICBitmapEncoderNoCache));
               IFS(piBitmapEncoder->CreateNewFrame(&piBitmapFrameEncode, &piPropertyBag));
            
               // This is how you customize the a LEAD WIC Encoder property bag.
               if(SUCCEEDED(hr))
               {        
                  ULONG uCount = 0;
                  hr = piPropertyBag->CountProperties(&uCount);
                  PROPBAG2 *pBag = new PROPBAG2[uCount];
                  ZeroMemory(pBag, sizeof(*pBag));
            
                  VARIANT *pValue = new VARIANT[uCount];
                  ZeroMemory(pValue, sizeof(*pValue));
            
                  HRESULT *pErrors = new HRESULT[uCount];
                  ZeroMemory(pErrors, sizeof(*pErrors));
            
                  IFS(piPropertyBag->GetPropertyInfo(0, uCount, pBag, &uCount));
                  IFS(piPropertyBag->Read(uCount, pBag, NULL, pValue, pErrors));
                  if (SUCCEEDED(hr))
                  {
                     for (ULONG u = 0; u < uCount; u++)
                     {
                        if (wcscmp(pBag[u].pstrName, L"XResolution")== 0)
                        {
                           pValue[u].uintVal = 300;
                           piPropertyBag->Write(1, pBag+u, pValue+u);
                        }
                        if (wcscmp(pBag[u].pstrName, L"YResolution")== 0)
                        {
                           pValue[u].uintVal = 300;
                           piPropertyBag->Write(1, pBag+u, pValue+u);
                        }
                    }
                  }
                  //Cleanup
                  DELETE_POINTER(pBag);
                  DELETE_POINTER(pValue);
                  DELETE_POINTER(pErrors);
            
                  IFS(piBitmapFrameEncode->Initialize(piPropertyBag));
               }
            
               // Now create the image data that we will write
               UINT uiWidth = 256;
               UINT uiHeight = 256;
               IFS(piBitmapFrameEncode->SetSize(uiWidth, uiHeight));
               WICPixelFormatGUID formatGUID = GUID_WICPixelFormat24bppBGR;
               IFS(piBitmapFrameEncode->SetPixelFormat(&formatGUID));
            
               if (SUCCEEDED(hr))
               {
                  // We're expecting to write out 24bppRGB. Fail if the encoder cannot do it.
                  hr = IsEqualGUID(formatGUID, GUID_WICPixelFormat24bppBGR) ? S_OK : E_FAIL;
               }
            
               if (SUCCEEDED(hr))
               {
                  UINT cbStride = (uiWidth * 24 + 7)/8;
                  UINT cbBufferSize = uiHeight * cbStride;
                  BYTE *pbBuffer = new BYTE[cbBufferSize];
            
                  if (pbBuffer != NULL)
                  {
                     for (UINT i = 0; i < cbBufferSize; i++)
                     {
                        pbBuffer[i] = static_cast<BYTE>(rand());
                     }
                     hr = piBitmapFrameEncode->WritePixels(uiHeight, cbStride, cbBufferSize, pbBuffer);
                     delete[] pbBuffer;
                  }
                  else
                  {
                     hr = E_OUTOFMEMORY;
                  }
               }
            
               // Commit the changes to the stream
               IFS(piBitmapFrameEncode->Commit());   
               IFS(piBitmapEncoder->Commit());
            
               RELEASE_INTERFACE(piBitmapFrameEncode);
               RELEASE_INTERFACE(piBitmapEncoder);
               RELEASE_INTERFACE(piImagingFactory);
               RELEASE_INTERFACE(piPropertyBag);
               RELEASE_INTERFACE(piStream);
            
               MessageBox(hWnd, csExampleName, csExampleName, MB_OK);
               return hr;
            }
                    

See Also

Reference

LEAD WIC-Enabled Codecs Overview
Registering a LEAD WIC-Enabled Codec
LEAD Bitmap Encoder Property Bag
LEAD Bitmap Encoder Property Bag: Jpeg2000 Specific Options
LEAD Bitmap Encoder Property Bag: Jbig2 Specific Options

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.