Compartir a través de


DpiHelper Class

Definition

Caution

Use Microsoft.VisualStudio.Utilities.DpiAwareness instead.

Helper class providing static properties, static methods and extension methods for scaling coordinates and images according to current System DPI set in Windows's Display Properties. The class scales images designed for 100% zoom levels (96dpi).

This class should be used by code running inside Visual Studio or other appids. The class provides public static properties and methods for easy binding/calling, and public static extension methods; the actual scaling implementation is delegated to the DpiHelper class from Microsoft.VisualStudio.Utilities.

This class allows the user to override the shell default scaling algorithms via registry settings under the running appid's hive. E.g. The user can set ImageScaling125, ImageScaling200, etc with values from ImageScalingMode enumeration to control the scaling algorithm used for managed Image objects at 125% and 200%. Similarly, the user can set BitmapScaling150, BitmapScaling200, etc to control the scaling algorithm of WPF ImageSources. And the user can set boolean registry values like UseBitmapPreScaling250 to control whether image scaling at 250% should be done in 2 steps, with NearestNeighbor up to the largest 100% multiple (200%), and from there with the algorithm specified by BitmapScaling250.

public ref class DpiHelper abstract sealed
public ref class DpiHelper abstract sealed
class DpiHelper abstract sealed
public static class DpiHelper
[System.Obsolete("Use Microsoft.VisualStudio.Utilities.DpiAwareness instead.")]
public static class DpiHelper
type DpiHelper = class
[<System.Obsolete("Use Microsoft.VisualStudio.Utilities.DpiAwareness instead.")>]
type DpiHelper = class
Public Module DpiHelper
Inheritance
DpiHelper
Attributes

Properties

BitmapScalingMode

Retuns the BitmapScalingMode algorithm to be used for resizing images in WPF. 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\BitmapScalingXXX = (BitmapScalingMode)value, with XXX the zoom factor in percents, e.g. BitmapScaling150, etc. Note that for WPF scaling, there is an additional registry value that applies for zoom factors > 200%, UseBitmapPreScalingXXX

DeviceDpiX

The screen's (device) current horizontal DPI

DeviceDpiY

The screen's (device) current vertical DPI

DeviceToLogicalUnitsScalingFactorX

Microsoft internal use only.

DeviceToLogicalUnitsScalingFactorY

Microsoft internal use only.

DpiScalePercentX

Gets the DPI scale percent for the horizontal scale.

DpiScalePercentY

Gets the DPI scale percent for the vertical scale.

ImageScalingMode

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

Instance

Gets an instance of DpiHelper.

IsScalingRequired

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

LogicalDpiX

The helper's logical horizontal DPI

LogicalDpiY

The helper's logical vertical DPI

LogicalToDeviceUnitsScalingFactorX

Microsoft internal use only.

LogicalToDeviceUnitsScalingFactorY

Microsoft internal use only.

PreScaledImageLayoutTransformScaleX

Return 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

Return 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

Microsoft internal use only.

TransformToDevice

Microsoft internal use only.

UsePreScaledImages

Returns 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)
Obsolete.

Extension method for System.Drawing.Bitmap that creates and returns a new bitmap strip 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)
Obsolete.

Extension method for System.Drawing.Bitmap that creates and returns a new bitmap strip scaled for the device units, using NearestNeighbor interpolation. 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)
Obsolete.

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)
Obsolete.

Extension method for System.Drawing.Image that creates and returns a new bitmap or metafile 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(Image, ImageScalingMode)
Obsolete.

Extension method for System.Drawing.Image that creates and returns a new bitmap or metafile 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)
Obsolete.

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)
Obsolete.

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)
Obsolete.

Extension method for Point that returns a new Point with the input's coordinates converted from device units to logical units.

DeviceToLogicalUnits(Rect)
Obsolete.

Extension method for Rect that returns a new Rect with the input's coordinates converted from device units to logical units.

DeviceToLogicalUnits(Size)
Obsolete.

Extension method for Size that returns a new Size with the input's dimensions converted from device units to logical units.

DeviceToLogicalUnits(Thickness)
Obsolete.

Extension method for Thickness that 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)

Transforms a horizontal coordinate from device to logical units

DeviceToLogicalUnitsY(Double)

Transforms a vertical coordinate from device to logical units

DeviceToLogicalUnitsY(Int32)

Transforms a vertical integer coordinate from device to logical units

DeviceToLogicalUnitsY(Single)

Transforms a vertical coordinate from device to logical units

GetDeviceActualSize(FrameworkElement)
Obsolete.

Extension method for FrameworkElement that returns its Size in device units

GetDeviceHeight(Window)
Obsolete.

Extension method for Window that returns its Height in device units

GetDeviceLeft(Window)
Obsolete.

Extension method for Window that returns its Left coordinate in device units

GetDeviceRect(Window)
Obsolete.

Extension method for Window that returns its Rectangle in device units

GetDeviceTop(Window)
Obsolete.

Extension method for Window that returns its Top coordinate in device units

GetDeviceWidth(Window)
Obsolete.

Extension method for Window that returns its Width in device units

LogicalToDeviceUnits(Bitmap, Color, ImageScalingMode)

Converts (if necessary) the image by scaling it to device units. When displayed on the device, the scaled image will have same size as the original image would have when displayed at 96dpi.

LogicalToDeviceUnits(Bitmap, ImageScalingMode)

Converts (if necessary) the image by scaling it to device units. When displayed on the device, the scaled image will have same size as the original image would have when displayed at 96dpi.

LogicalToDeviceUnits(Bitmap, Size, Color, ImageScalingMode)

Converts (if necessary) the image strip to device units, using NearestNeighbor interpolation.. 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.

LogicalToDeviceUnits(Bitmap, Size, ImageScalingMode)

Converts (if necessary) the image strip to device units, using NearestNeighbor interpolation.. 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.

LogicalToDeviceUnits(Icon, ImageScalingMode)

Converts (if necessary) the icon by scaling it to device units. When displayed on the device, the scaled icon will have same size as the original icon would have when displayed at 96dpi.

LogicalToDeviceUnits(Image, Color, ImageScalingMode)

Converts (if necessary) the image by scaling it to device units. When displayed on the device, the scaled image will have same size as the original image would have when displayed at 96dpi.

LogicalToDeviceUnits(Image, ImageScalingMode)

Converts (if necessary) the image by scaling it to device units. When displayed on the device, the scaled image will have same size as the original image would have when displayed at 96dpi.

LogicalToDeviceUnits(ImageList, Color, ImageScalingMode)

Converts (if necessary) the imagelist by scaling it to device units. When displayed on the device, the scaled imagelist will have same size as the original imagelist would have when displayed at 96dpi.

LogicalToDeviceUnits(ImageList, ImageScalingMode)

Converts (if necessary) the imagelist by scaling it to device units. When displayed on the device, the scaled imagelist will have same size as the original imagelist would have when displayed at 96dpi.

LogicalToDeviceUnits(Point)
Obsolete.

Extension method for Point that returns a new Point with the input's coordinates converted from logical units to device units.

LogicalToDeviceUnits(Point)
Obsolete.

Extension method for System.Drawing.Point that returns a new Point with the input's coordinates converted from logical units to device units.

LogicalToDeviceUnits(PointF)
Obsolete.

Extension method for System.Drawing.PointF that returns a new PointF with the input's coordinates converted from logical units to device units.

LogicalToDeviceUnits(Rect)
Obsolete.

Extension method for Rect that returns a new Rect with the input's coordinates converted from logical units to device units.

LogicalToDeviceUnits(Rectangle)
Obsolete.

Extension method for System.Drawing.Rectangle that returns a new Rectangle with the input's coordinates converted from logical units to device units.

LogicalToDeviceUnits(RectangleF)
Obsolete.

Extension method for System.Drawing.RectangleF that returns a new RectangleF with the input's coordinates converted from logical units to device units.

LogicalToDeviceUnits(Size)
Obsolete.

Extension method for Size that returns a new Size with the input's dimensions converted from logical units to device units.

LogicalToDeviceUnits(Size)
Obsolete.

Extension method for System.Drawing.Size that returns a new Size with the input's coordinates converted from logical units to device units.

LogicalToDeviceUnits(SizeF)
Obsolete.

Extension method for System.Drawing.SizeF that returns a new SizeF with the input's coordinates converted from logical units to device units.

LogicalToDeviceUnits(Thickness)
Obsolete.

Extension method for Thickness that returns a new Thickness with the input's dimensions converted from logical units to device units.

LogicalToDeviceUnitsX(Double)

Transforms a horizontal coordinate from logical to device units

LogicalToDeviceUnitsX(Int32)

Transforms a horizontal integer coordinate from logical to device units by scaling it up for current DPI and rounding to nearest integer value

LogicalToDeviceUnitsX(Single)

Transforms a horizontal coordinate from logical to device units

LogicalToDeviceUnitsY(Double)

Transforms a vertical coordinate from logical to device units

LogicalToDeviceUnitsY(Int32)

Transforms a vertical integer coordinate from logical to device units by scaling it up for current DPI and rounding to nearest integer value

LogicalToDeviceUnitsY(Single)

Transforms a vertical coordinate from logical to device units

RoundToDeviceUnitsX(Double)

Returns the closest value in logical units that will be converted to an integer value when converted to horizontal device units

RoundToDeviceUnitsY(Double)

Returns the closest value in logical units that will be converted to an integer value when converted to vertical device units

ScaleLogicalImageForDeviceSize(ImageSource, Size, BitmapScalingMode)

Scale a WPF image to the indicated size, using the specified scalingMode

SetDeviceHeight(Window, Double)
Obsolete.

Extension method for Window that sets its Height using device units

SetDeviceLeft(Window, Double)
Obsolete.

Extension method for Window that sets its Left coordinate using device units

SetDeviceTop(Window, Double)
Obsolete.

Extension method for Window that sets its Top coordinate using device units

SetDeviceWidth(Window, Double)
Obsolete.

Extension method for Window that sets its Width using device units

Applies to