Table of Contents

Method CreateCompatibleDeviceContext

Namespace
PaintDotNet.Direct2D1
Assembly
PaintDotNet.Windows.dll

CreateCompatibleDeviceContext(SizeFloat?, SizeInt32?, DevicePixelFormat?, CompatibleDeviceContextOptions)

Creates a bitmap device context for use during intermediate offscreen drawing that is compatible with the current render target.

ICompatibleDeviceContext CreateCompatibleDeviceContext(SizeFloat? desiredSize = null, SizeInt32? desiredPixelSize = null, DevicePixelFormat? desiredPixelFormat = null, CompatibleDeviceContextOptions options = CompatibleDeviceContextOptions.None)

Parameters

desiredSize SizeFloat?

The desired size of the new device context (in device-independent pixels), if it should be different from the original device context. For more info, see the Remarks section.

desiredPixelSize SizeInt32?

The desired size of the new device context in pixels if it should be different from the original device context. For more information, see the Remarks section.

desiredPixelFormat DevicePixelFormat?

The desired pixel format and alpha mode of the new device context. If the pixel format is set to Unknown, the new device context uses the same pixel format as the original device context. If the alpha mode is Unknown, the alpha mode of the new device context defaults to Premultiplied. For information about supported pixel formats, see Supported Pixel Formats and Alpha Modes.

options CompatibleDeviceContextOptions

A value that specifies whether the new render target must be compatible with GDI.

Returns

ICompatibleDeviceContext

The new bitmap device context.

Remarks

The pixel size and DPI of the new render target can be altered by specifying values for desiredSize or desiredPixelSize.

  • If desiredSize is specified but desiredPixelSize is not, the pixel size is computed from the desired size using the parent target DPI. If the desiredSize maps to a integer-pixel size, the DPI of the compatible render target is the same as the DPI of the parent target. If desiredSize maps to a fractional-pixel size, the pixel size is rounded up to the nearest integer and the DPI for the compatible device context is slightly higher than the DPI of the parent device context. In all cases, the coordinate (desiredSize.width, desiredSize.height) maps to the lower-right corner of the compatible device context.
  • If the desiredPixelSize is specified and desiredSize is not, the DPI of the new render target is the same as the original device context.
  • If both desiredSize and desiredPixelSize are specified, the DPI of the new device context is computed to account for the difference in scale.
  • If neither desiredSize nor desiredPixelSize is specified, the new render target size and DPI match the original device context.