DpiHelper Class

Definition

Warning

This API is now obsolete.

A helper class for scaling coordinates and images according to current DPI scaling set in Windows for the screen.

public ref class DpiHelper
[Windows::Foundation::Metadata::WebHostHidden]
public ref class DpiHelper
[Windows::Foundation::Metadata::WebHostHidden]
class DpiHelper
[System.Obsolete("Use Microsoft.VisualStudio.Utilities.DpiAwareness instead.")]
public class DpiHelper
type DpiHelper = class
Public Class DpiHelper
Inheritance
DpiHelper
Derived
Attributes

Remarks

This class can be used in assemblies that can't take a dependency on Microsoft.VisualStudio.Shell.14.0 (or later). This class doesn't use any Visual Studio-specific interfaces or services. The code running in Visual Studio or other appids should not be using this class. Instead, it should use the static DpiHelper class from Microsoft.VisualStudio.PlatformUI namespace from the Visual Studio Framework assembly. Usually the code needing Dpi scaling functionality provided by this class should access it by calling the members of the static DpiHelper.Default instance.

Constructors

DpiHelper(Double)

Initializes a new instance of DpiHelper.

Fields

DefaultLogicalDpi

The default logical DPI.

Properties

BitmapScalingMode

The BitmapScalingMode.

Default

eturns a DpiHelper class suitable for scaling images designed for 100% DPI zoom levels (96dpi).

DeviceDpiX

Gets the screen's (device) current horizontal DPI.

DeviceDpiY

The screen's (device) current vertical DPI.

DeviceToLogicalUnitsScalingFactorX

Converts to the horizontal logical units scaling factor.

DeviceToLogicalUnitsScalingFactorY

Converts to the vertical logical units scaling factor.

DpiScalePercentX
DpiScalePercentY
ImageScalingMode

Gets the ImageScalingMode algorithm to be used for resizing images in WinForms/Win32. This allows the shell to control the algorithm depending on the DPI zoom scale, and allows the user to override it via registry settings like General\ImageScalingXXX = (ImageScalingMode)value, with XXX the zoom factor in percents, e.g. ImageScaling150, etc.

IsScalingRequired

Determines whether scaling is required when converting between logical-device units

LogicalDpiX

Gets the helper's logical horizontal DPI.

LogicalDpiY

Gets the helper's vertical horizontal DPI.

LogicalToDeviceUnitsScalingFactorX
LogicalToDeviceUnitsScalingFactorY
PreScaledImageLayoutTransformScaleX

Gets the horizontal scale value that should be used with a LayoutTransform/ScaleTransform to scale back an image pre-scaled in HighDPI with DpiPrescaleImageSourceConverter in order to obtain crisp results.

PreScaledImageLayoutTransformScaleY

Gets the vertical scale value that should be used with a LayoutTransform/ScaleTransform to scale back an image pre-scaled in HighDPI with DpiPrescaleImageSourceConverter in order to obtain crisp results.

TransformFromDevice
TransformToDevice
UsePreScaledImages

Determines whether images should be pre-scaled at zoom levels higher than 200%, using NearestNeighbor up to the largest multiple of 100%

Methods

CreateDeviceFromLogicalImage(Bitmap, Size, Color, ImageScalingMode)

Creates and returns a new bitmap strip from the logical Bitmap scaled for the device units. When displayed on the device, the scaled image strip will have same size as the original image strip would have when displayed at 96dpi. This should be used for converting imagelists bitmap strips instead of simply scaling the bitmap, because the resultant bitmap strip size may be different from just upscaling as bitmap N * Math.Round(width * dpiscale) != Math.Round(N * width * dpiscale). This may happen depending on the image width because dpiscale is a double not an int.

CreateDeviceFromLogicalImage(Bitmap, Size, ImageScalingMode)

Creates and returns a new bitmap strip from the logical Bitmap scaled for the device units. When displayed on the device, the scaled image strip will have same size as the original image strip would have when displayed at 96dpi. This should be used for converting imagelists bitmap strips instead of simply scaling the bitmap, because the resultant bitmap strip size may be different from just upscaling as bitmap N * Math.Round(width * dpiscale) != Math.Round(N * width * dpiscale). This may happen depending on the image width because dpiscale is a double not an int.

CreateDeviceFromLogicalImage(Icon, ImageScalingMode)

Creates and returns a new icon scaled for the device units. When displayed on the device, the scaled icon will have same size as the original icon would have when displayed at 96dpi.

CreateDeviceFromLogicalImage(Image, Color, ImageScalingMode)

Creates and returns a new ImageList scaled for the device units. When displayed on the device, the scaled ImageList will have same size as the original ImageList would have when displayed at 96dpi.

CreateDeviceFromLogicalImage(Image, ImageScalingMode)

Creates and returns a new bitmap or metafile from the logical Image scaled for the device units. When displayed on the device, the scaled image will have same size as the original image would have when displayed at 96dpi.

CreateDeviceFromLogicalImage(ImageList, Color, ImageScalingMode)

Creates and returns a new ImageList scaled for the device units. When displayed on the device, the scaled ImageList will have same size as the original imagelist would have when displayed at 96dpi.

CreateDeviceFromLogicalImage(ImageList, ImageScalingMode)

Creates and returns a new ImageList scaled for the device units. When displayed on the device, the scaled ImageList will have same size as the original ImageList would have when displayed at 96dpi.

DeviceToLogicalUnits(Point)

Returns a new Point with the input's coordinates converted from device units to logical units.

DeviceToLogicalUnits(Rect)

Returns a new Rect with the input's coordinates converted from device units to logical units.

DeviceToLogicalUnits(Size)

Returns a new Size with the input's dimensions converted from device units to logical units.

DeviceToLogicalUnits(Thickness)

Returns a new Thickness with the input's dimensions converted from device units to logical units.

DeviceToLogicalUnitsX(Double)

Transforms a horizontal coordinate from device to logical units.

DeviceToLogicalUnitsX(Int32)

Transforms a horizontal integer coordinate from device to logical units.

DeviceToLogicalUnitsX(Single)
DeviceToLogicalUnitsY(Double)

Transforms a vertical coordinate from device to logical units.

DeviceToLogicalUnitsY(Int32)

Transforms a vertical coordinate from device to logical units.

DeviceToLogicalUnitsY(Single)

Transforms a vertical coordinate from device to logical units.

GetBitmapScalingModeOverride(Int32, BitmapScalingMode)

Gets the bitmap scaling mode override.

GetDeviceActualSize(FrameworkElement)

Gets the FrameworkElement's Size in device units.

GetDeviceHeight(Window)

Gets the window's height in device units.

GetDeviceLeft(Window)

Gets the window's left coordinate in device units.

GetDeviceRect(Window)

Gets the window's rectangle in device units.

GetDeviceTop(Window)

Gets the window's top in device units.

GetDeviceWidth(Window)

Gets the window's width in device units.

GetHelper(Int32)
GetImageScalingModeOverride(Int32, ImageScalingMode)
GetUsePreScaledImagesOverride(Int32, Boolean)
LogicalToDeviceUnits(Bitmap, Color, ImageScalingMode)
LogicalToDeviceUnits(Bitmap, ImageScalingMode)
LogicalToDeviceUnits(Bitmap, Size, Color, ImageScalingMode)
LogicalToDeviceUnits(Bitmap, Size, ImageScalingMode)
LogicalToDeviceUnits(Icon, ImageScalingMode)
LogicalToDeviceUnits(Image, Color, ImageScalingMode)
LogicalToDeviceUnits(Image, ImageScalingMode)
LogicalToDeviceUnits(ImageList, Color, ImageScalingMode)
LogicalToDeviceUnits(ImageList, ImageScalingMode)
LogicalToDeviceUnits(Point)
LogicalToDeviceUnits(Point)
LogicalToDeviceUnits(PointF)
LogicalToDeviceUnits(Rect)
LogicalToDeviceUnits(Rectangle)
LogicalToDeviceUnits(RectangleF)
LogicalToDeviceUnits(Size)
LogicalToDeviceUnits(Size)
LogicalToDeviceUnits(SizeF)
LogicalToDeviceUnits(Thickness)
LogicalToDeviceUnitsX(Double)
LogicalToDeviceUnitsX(Int32)
LogicalToDeviceUnitsX(Single)
LogicalToDeviceUnitsY(Double)
LogicalToDeviceUnitsY(Int32)
LogicalToDeviceUnitsY(Single)
RoundToDeviceUnitsX(Double)
RoundToDeviceUnitsY(Double)
ScaleLogicalImageForDeviceSize(ImageSource, Size, BitmapScalingMode)
SetDeviceHeight(Window, Double)
SetDeviceLeft(Window, Double)
SetDeviceTop(Window, Double)
SetDeviceWidth(Window, Double)

Applies to