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 enumerationType and default valueDescription

Scale

D2D1_SCALE_PROP_SCALE

D2D1_VECTOR_2F

{1.0f, 1.0f}

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.

CenterPoint

D2D1_SCALE_PROP_CENTER_POINT

D2D1_VECTOR_2F

{0.0f, 0.0f}

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.

BorderMode

D2D1_SCALE_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.

Sharpness

D2D1_SCALE_PROP_SHARPNESS

FLOAT

0.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 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.

InterpolationMode

D2D1_SCALE_PROP_INTERPOLATION_MODE

D2D1_SCALE_INTERPOLATION_MODE

D2D1_SCALE_INTERPOLATION_MODE_LINEAR

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.

 

Border modes

NameDescription
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

EnumerationDescription
D2D1_SCALE_INTERPOLATION_MODE_NEAREST_NEIGHBORSamples the nearest single point and uses that. This mode uses less processing time, but outputs the lowest quality image.
D2D1_SCALE_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_SCALE_INTERPOLATION_MODE_CUBICUses 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_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_SCALE_INTERPOLATION_MODE_ANISOTROPICUses anisotropic filtering to sample a pattern according to the transformed shape of the bitmap.
D2D1_SCALE_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_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.

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. All rights reserved.