SSDASDASADASDASDDASDAS

kasmer 66 Reputation points
2021-07-07T17:58:25.303+00:00

RESOLVED :")

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,523 questions
C++
C++
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,637 questions
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 12,231 Reputation points Microsoft Vendor
    2021-07-08T02:59:35.787+00:00

    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)
        {
            RETURN_INVALID_ARGUMENT_IF_NULL(imageResource);
    
            // 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.
            RETURN_HR_IF_FAILED(imageRectPath->SetAccessibilityShortDescription(shortDescription));
    
            // Set the image brush to be the fill brush for this path.
            RETURN_HR_IF_FAILED(imageRectPath->SetFillBrushLocal(imageBrush.Get()));
    
            // Get the list of visuals for this page...
            RETURN_HR_IF_FAILED(xpsOMPage->GetVisuals(&pageVisuals));
    
            // ...and add the completed path to the list.
            RETURN_HR_IF_FAILED(pageVisuals->Append(imageRectPath.Get()));
    
            return S_OK;
        }
    
    0 comments No comments

0 additional answers

Sort by: Most helpful