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 8
Windows 8
A Microsoft operating system.
201 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,221 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 8,666 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