kasmer 66 Reputation points


Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,479 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,599 questions
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 11,746 Reputation points Microsoft Vendor

    You can refer to Microsoft Github Sample:print-oem-samples which Adds Texts and Images To Visual Collection.
    The Following is AddImageToVisualCollection:

     /*  PrintWorkflowXpsReceiver::AddImageToVisualCollection
        *  If the source image is available in the XPS OM as an image resource, 
        *  it can be used to create an image brush object and added as the fill brush to the path
        *  that describes the image location and size in the page.
        *  Arguments:
        *      _In_ ComPtr<IXpsOMPage>  &xpsOMPage            XPS Page Object Model
        *      _In_ IXpsOMImageResource *imageResource        Image resource to add to the page
        *      _In_ XPS_SIZE            *imageWidthAndHeight  Pixel width and height of image
        *      _In_ FLOAT                dotsPerInchX         Image X resolution in dots per inch    
        *      _In_ FLOAT                dotsPerInchY         Image XY resolution in dots per inch  
        *      _In_ XPS_RECT             rect                 Image size and location
        *      _In_ LPCWSTR              shortDescription     Short text description of image
        *  Returns:
        *       E_INVALIDARG      Invalid imageResource
        *       S_OK              Success
        *       Other             HRESULT of error
        HRESULT PrintWorkflowXpsReceiver::AddImageToVisualCollection(
                                                                     _In_ ComPtr<IXpsOMPage> &xpsOMPage,
                                                                     _In_ IXpsOMImageResource *imageResource,
                                                                     _In_ XPS_SIZE *imageWidthAndHeight,
                                                                     _In_ FLOAT dotsPerInchX,
                                                                     _In_ FLOAT dotsPerInchY,
                                                                     _In_ XPS_RECT rect,
                                                                     _In_ LPCWSTR shortDescription)
            // initialize viewport values 
            XPS_RECT    viewPort = { 0.0,0.0,0.0,0.0 };
            // initialize viewbox values
            XPS_RECT    viewBox = { 0.0,0.0,0.0,0.0 };
            // These are part of this code example.
            ComPtr<IXpsOMPath> imageRectPath;
            ComPtr<IXpsOMImageBrush> imageBrush;
            ComPtr<IXpsOMVisualCollection> pageVisuals;
            // Describe image source dimensions and set viewbox to be the 
            // entire image DIP width of image. 
            //  Example: 
            //    600 image pixels, 300 dpi -> 2 inches -> 2 * 96 = 192 DIP width
            viewBox.width = imageWidthAndHeight->width * 96.0f / dotsPerInchX;
            viewBox.height = imageWidthAndHeight->height * 96.0f / dotsPerInchY;
            // destination rectangle
            viewPort.x = rect.x;
            viewPort.y = rect.y;
            viewPort.width = rect.width;
            viewPort.height = rect.height;
            // Create the image brush.
            RETURN_HR_IF_FAILED(_xpsOMObjectFactory->CreateImageBrush(imageResource, &viewBox, &viewPort, imageBrush.GetAddressOf()));
            // Create the path that describes the outline of the image on the page.
            RETURN_HR_IF_FAILED(CreateRectanglePath(rect, imageRectPath.GetAddressOf()));
            // Set the accessibility description for the path object as required.
            // Set the image brush to be the fill brush for this path.
            // Get the list of visuals for this page...
            // ...and add the completed path to the list.
            return S_OK;
    0 comments No comments

0 additional answers

Sort by: Most helpful