Редагувати

Поділитися через


3D perspective transform effect

Use the 3D perspective transform effect to rotate the image in 3 dimensions as if viewed from a distance.

The 3D perspective transform is more convenient than the 3D transform effect, but only exposes a subset of the functionality. You can compute a full 3D transformation matrix and apply a more arbitrary transform matrix to an image using the 3D transform effect.

The CLSID for this effect is CLSID_D2D13DPerspectiveTransform.

Example image

Before
the image before the effect.
After
the image after the effect.
ComPtr<ID2D1Effect> perspectiveTransformEffect;
m_d2dContext->CreateEffect(CLSID_D2D13DPerspectiveTransform, &perspectiveTransformEffect);

perspectiveTransformEffect->SetInput(0, bitmap);

perspectiveTransformEffect->SetValue(D2D1_3DPERSPECTIVETRANSFORM_PROP_PERSPECTIVE_ORIGIN, D2D1::Vector3F(0.0f, 192.0f, 0.0f));
perspectiveTransformEffect->SetValue(D2D1_3DPERSPECTIVETRANSFORM_PROP_ROTATION, D2D1::Vector3F(0.0f, 30.0f, 0.0f));

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

Effect properties

Display name and index enumeration Description
InterpolationMode
D2D1_3DPERSPECTIVETRANSFORM_PROP_INTERPOLATION_MODE
The interpolation mode the effect uses on the image. There are 5 scale modes that range in quality and speed.
Type is D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE.
Default value is D2D1_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE_LINEAR.
BorderMode
D2D1_3DPERSPECTIVETRANSFORM_PROP_BORDER_MODE
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.
Depth
D2D1_3DPERSPECTIVETRANSFORM_PROP_DEPTH
The distance from the PerspectiveOrigin to the projection plane. The value specified in DIPs and must be greater than 0.
Type is FLOAT.
Default value is 1000.0f.
PerspectiveOrigin
D2D1_3DPERSPECTIVETRANSFORM_PROP_PERSPECTIVE_ORIGIN
The X and Y location of the viewer in the 3D scene. This property is a D2D1_VECTOR_2F defined as: (point X, point Y). The units are in DIPs.
You set the Z value with the Depth property.
Type is D2D1_VECTOR_2F.
Default value is {0.0f, 0.0f}.
LocalOffset
D2D1_3DPERSPECTIVETRANSFORM_PROP_LOCAL_OFFSET
A translation the effect performs before it rotates the projection plane. This property is a D2D1_VECTOR_3F defined as: (X, Y, Z). The units are in DIPs.
Type is D2D1_VECTOR_3F.
Default value is {0.0f, 0.0f, 0.0f}.
GlobalOffset
D2D1_3DPERSPECTIVETRANSFORM_PROP_GLOBAL_OFFSET
A translation the effect performs after it rotates the projection plane. This property is a D2D1_VECTOR_3F defined as: (X, Y, Z). The units are in DIPs.
Type is D2D1_VECTOR_3F.
Default value is {0.0f, 0.0f, 0.0f}.
RotationOrigin
D2D1_3DPERSPECTIVETRANSFORM_PROP_ROTATION_ORIGIN
The center point of the rotation the effect performs. This property is a D2D1_VECTOR_3F defined as: (X, Y, Z). The units are in DIPs.
Type is D2D1_VECTOR_3F.
Default value is {0.0f, 0.0f, 0.0f}.
Rotation
D2D1_3DPERSPECTIVETRANSFORM_PROP_ROTATION
The angles of rotation for each axis. This property is a D2D1_VECTOR_3F defined as: (X, Y, Z). The units are in degrees.
Type is D2D1_VECTOR_3F.
Default value is {0.0f, 0.0f, 0.0f}.

Interpolation modes

Enumeration Description
D2D1_3DPERSPECTIVETRANSFORM_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_3DPERSPECTIVETRANSFORM_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_3DPERSPECTIVETRANSFORM_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_3DPERSPECTIVETRANSFORM_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_3DPERSPECTIVETRANSFORM_INTERPOLATION_MODE_ANISOTROPIC Uses anisotropic filtering to sample a pattern according to the transformed shape of the bitmap.

Note

If you don't select a mode, the effect defaults to D2D1_3DPERSPECTIVETRANSFORM_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.

Border modes

Name Description
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.

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.

Requirements

Requirement Value
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]
Header d2d1effects.h
Library d2d1.lib, dxguid.lib

ID2D1Effect