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 development | Windows API - Win32
Windows for business | Windows Client for IT Pros | User experience | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,731 Reputation points Microsoft External Staff
    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.