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
- Effect properties
- Border modes
- Interpolation modes
- Output bitmap
- Related topics
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:
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.
|Display name and index enumeration||Description|
|The interpolation mode used to scale the image. There are 6 scale modes that range in quality and speed.
Type is D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE.
Default value is D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_LINEAR.
|The mode used to calculate the border of the image, soft or hard. See Border modes for more info.
Type is D2D1_BORDER_MODE.
Default value is D2D1_BORDER_MODE_SOFT.
|The 3x2 matrix to transform the image using the Direct2D matrix transform.
Type is D2D1_MATRIX_3X2_F.
Default value is Matrix3x2F::Identity().
|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.
Type is FLOAT.
Default value is 1.0f.
|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.
|D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_NEAREST_NEIGHBOR||Samples the nearest single point and uses that. This mode uses less processing time, but outputs the lowest quality image.|
|D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_LINEAR||Uses 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_CUBIC||Uses 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_LINEAR||Uses 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_ANISOTROPIC||Uses anisotropic filtering to sample a pattern according to the transformed shape of the bitmap.|
|D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC||Uses 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.|
If you don't select a mode, the effect defaults to D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_LINEAR.
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.
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.
|Minimum supported client||Windows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]|
|Minimum supported server||Windows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]|