Why is my bitmap mask rendered stretched?

JWG 146 Reputation points
2023-08-28T00:04:52.3833333+00:00

What would cause either the bitmap or bitmap mask to be stretched, so they do not align?

The image is for testing purposes.masked


	hr = renderTarget->CreateBitmapBrush(bmap, bmapBrushProps, &bmapBrush);

		hr = renderTarget->CreateBitmapBrush(
			bmapMask, bmapBrushProps, &bmapMaskBrush);


				deviceContext->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);

				deviceContext->FillOpacityMask(
					bmapMask,
					bmapBrush,
					D2D1_OPACITY_MASK_CONTENT_GRAPHICS,
					&destRect,
					NULL
				);

				deviceContext->SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,277 questions
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,576 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,721 Reputation points Microsoft Vendor
    2023-08-29T02:40:48.4233333+00:00
    1. There is a transform on ID2D1RenderTarget. ID2D1RenderTarget::SetTransform
    2. The most important thing is to

    Compute the bounds we will pass to FillOpacityMask (which are in Device Independent Pixels) based on DPI.

    for more information, see the two examples.

    1 person found this answer helpful.

  2. JWG 146 Reputation points
    2023-08-28T21:13:18.07+00:00

    Okay, so I either set the destination and source to NULL, or just specify the source rectangle.

    masked

    I just need to work on the scale. Thanks.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.