2D affine transform effect

The 2D affine transform effect applies a spatial transform to a image based on a 3X2 matrix using the Direct2D matrix transform and any of six interpolation modes. You can use this effect to rotate, scale, skew, or translate an image. Or, you can combine these operations. Affine transfers preserve parallel lines and the ratio of distances between any three points in an image.

The CLSID for this effect is CLSID_D2D12DAffineTransform.

Example image

Before
The image before the effect.
After
The image after the transform.

 


ComPtr<ID2D1Effect> affineTransformEffect;
m_d2dContext->CreateEffect(CLSID_D2D12DAffineTransform, &affineTransformEffect);

affineTransformEffect->SetInput(0, bitmap);

D2D1_MATRIX_3X2_F matrix = D2D1::Matrix3x2F(0.9f, -0.1f,   0.1f, 0.9f,   8.0f, 45.0f);

affineTransformEffect->SetValue(D2D1_2DAFFINETRANSFORM_PROP_TRANSFORM_MATRIX, matrix);

m_d2dContext->BeginDraw();
m_d2dContext->DrawImage(affineTransformEffect.Get());
m_d2dContext->EndDraw();

This effect performs this matrix operation:

Affine matrix operation

Although the input matrix is defined as a 3x2 matrix, the last column is padded with 0, 0 and 1 to produce a square matrix. This allows for matrix multiplication, so that transforms can be concatenated into a single matrix.

Effect properties

Display name and index enumerationType and default valuesDescription

InterpolationMode

D2D1_2DAFFINETRANSFORM_PROP_INTERPOLATION_MODE

D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE

D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_LINEAR

The interpolation mode used to scale the image. There are 6 scale modes that range in quality and speed.

BorderMode

D2D1_2DAFFINETRANSFORM_PROP_BORDER_MODE

D2D1_BORDER_MODE

D2D1_BORDER_MODE_SOFT

The mode used to calculate the border of the image, soft or hard. See Border modes for more info.

TransformMatrix

D2D1_2DAFFINETRANSFORM_PROP_TRANSFORM_MATRIX

D2D1_MATRIX_3X2_F

Matrix3x2F::Identity()

The 3x2 matrix to transform the image using the Direct2D matrix transform.

Sharpness

D2D1_2DAFFINETRANSFORM_PROP_SHARPNESS

FLOAT

1.0f

In the high quality cubic interpolation mode, the sharpness level of the scaling filter as a float between 0 and 1. The values are unitless. You can use sharpness to adjust the quality of an image when you scale the image.

The sharpness factor affects the shape of the kernel. The higher the sharpness factor, the smaller the kernel.

Note  This property affects only the high quality cubic interpolation mode.

 

Border modes

NameDescription
D2D1_BORDER_MODE_SOFT

The effect pads the image with transparent black pixels as it interpolates, resulting in a soft edge.

D2D1_BORDER_MODE_HARD

The effect clamps the output to the size of the input image.

 

Interpolation modes

EnumerationDescription
D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_NEAREST_NEIGHBORSamples the nearest single point and uses that. This mode uses less processing time, but outputs the lowest quality image.
D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_LINEARUses a four point sample and linear interpolation. This mode uses more processing time than the nearest neighbor mode, but outputs a higher quality image.
D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_CUBICUses a 16 sample cubic kernel for interpolation. This mode uses the most processing time, but outputs a higher quality image.
D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_MULTI_SAMPLE_LINEARUses 4 linear samples within a single pixel for good edge anti-aliasing. This mode is good for scaling down by small amounts on images with few pixels.
D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_ANISOTROPICUses anisotropic filtering to sample a pattern according to the transformed shape of the bitmap.
D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_HIGH_QUALITY_CUBICUses a variable size high quality cubic kernel to perform a pre-downscale the image if downscaling is involved in the transform matrix. Then uses the cubic interpolation mode for the final output.

 

Note  If you don't select a mode, the effect defaults to D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_LINEAR.

Note  Anisotropic mode generates mipmaps when scaling, however, if you set the Cached property to true on the effects that are input to this effect, the mipmaps won't be generated every time for sufficiently small images.

Output bitmap

The size of the output bitmap depends on the transform matrix that is applied to the image.

The effect performs the transform operation and then applies a bounding box around the result. The output bitmap is the size of the bounding box.

Sample code

For an example of this effect, download the Direct2D interpolation modes sample.

Requirements

Minimum supported clientWindows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]
Minimum supported serverWindows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]
Headerd2d1effects.h
Libraryd2d1.lib, dxguid.lib

 

Related topics

ID2D1Effect

 

 

Community Additions

ADD
Show:
© 2014 Microsoft