Scale effect

Use this effect to scale an image up or down. The effect has six scaling modes: nearest neighbor, linear, cubic, multi-sample linear, anisotropic, and high quality cubic.

The CLSID for this effect is CLSID_D2D1Scale.

Example image

This example shows the scale effect zooming in 2 times the input and cropping to the original size.

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

scaleEffect->SetInput(0, bitmap);

scaleEffect->SetValue(D2D1_SCALE_PROP_CENTER_POINT, D2D1::Vector2F(256.0f, 192.0f));
scaleEffect->SetValue(D2D1_SCALE_PROP_SCALE, D2D1::Vector2F(2.0f, 2.0f));

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

Effect properties

Display name and index enumeration Description
Scale
D2D1_SCALE_PROP_SCALE
The scale amount in the X and Y direction as a ratio of the output size to the input size. This property a D2D1_VECTOR_2Fdefined as: (X scale, Y scale). The scale amounts are FLOAT, unitless, and must be positive or 0.
The type is D2D1_VECTOR_2F.
The default value is {1.0f, 1.0f}.
CenterPoint
D2D1_SCALE_PROP_CENTER_POINT
The image scaling center point. This property is a D2D1_VECTOR_2F defined as: (point X, point Y). The units are in DIPs.
Use the center point property to scale around a point other than the upper-left corner.
The type is D2D1_VECTOR_2F.
The default value is {0.0f, 0.0f}.
BorderMode
D2D1_SCALE_PROP_BORDER_MODE
The mode used to calculate the border of the image, soft or hard. See Border modes for more info.
The type is D2D1_BORDER_MODE.
The default value is D2D1_BORDER_MODE_SOFT.
Sharpness
D2D1_SCALE_PROP_SHARPNESS
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 down.
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.
The type is FLOAT.
The default value is 0.0f.
InterpolationMode
D2D1_SCALE_PROP_INTERPOLATION_MODE
The interpolation mode the effect uses to scale the image. There are 6 scale modes that range in quality and speed. See Interpolation modes for more info.
The type is D2D1_SCALE_INTERPOLATION_MODE.
The default value is D2D1_SCALE_INTERPOLATION_MODE_LINEAR.

Border modes

Name Description
D2D1_BORDER_MODE_SOFT The effect pads the input image with transparent black pixels for samples outside of the input bounds when it applies the convolution kernel. This creates a soft edge for the image, and in the process expands the output bitmap by the size of the kernel.
D2D1_BORDER_MODE_HARD The effect extends the input image with a mirror-type border transform for samples outside of the input bounds. The size of the output bitmap is equal to the size of the input bitmap.

`

Interpolation modes

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

Note

If you don't select a mode, the effect defaults to D2D1_SCALE_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 location and size of the output bitmap depends on the specified scale factor and the center point.

You can calculate the size of the output bitmap using this equation:

BitmapSizex(Pixels)=Scalex*Original Bitmap Sizex (DIPs)*(UserDPI/96)
BitmapSizey(Pixels)=Scaley*Original Bitmap Sizey (DIPs)*(UserDPI/96)

The effect rounds fractions of pixels up to the nearest whole pixel.

The location of the bitmap is (0, 0) or the value of the center point property.

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