Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,652 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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;
}