Table of Contents

Method GetTarget

Namespace
PaintDotNet.Direct2D1
Assembly
PaintDotNet.Windows.dll

GetTarget()

Gets the target currently associated with the device context.

IDeviceImage? GetTarget()

Returns

IDeviceImage

The target currently associated with the device context.

Remarks

If a target is not associated with the device context, this method will return null.
If the currently selected target is a bitmap rather than a command list, the application can gain access to the initial bitmaps created by using one of the following methods: CreateHwndDeviceContext(in DeviceContextProperties, in HwndDeviceContextProperties), CreateBitmapDeviceContext(IBitmap, in DeviceContextProperties), CreateDCDeviceContext(in DeviceContextProperties), CreateCompatibleDeviceContext(SizeFloat?, SizeInt32?, DevicePixelFormat?, CompatibleDeviceContextOptions).
It is not possible for an application to destroy these bitmaps. All of these bitmaps are bindable as bitmap targets. However not all of these bitmaps can be used as bitmap sources for IDeviceContext methods.
CreateCompatibleDeviceContext(SizeFloat?, SizeInt32?, DevicePixelFormat?, CompatibleDeviceContextOptions) will always create bitmaps that are usable as a bitmap source.
When using IDCDeviceContext, BeginDraw() will copy from the HDC to the original bitmap associated with it. EndDraw() will copy from the original bitmap to the HDC.
IBitmap objects will be locked in the following circumstances:

  • BeginDraw has been called and the currently selected target bitmap is an IBitmap.
  • An IBitmap is set as the target of a device context after BeginDraw has been called and before EndDraw has been called.
  • Any of the IDeviceBitmap.Copy* methods are called with an IBitmap as either the source or detination.
IBitmap objects will be unlocked in the following circumstances:
  • EndDraw is called and the currently selected target bitmap is an IBitmap.
  • An IBitmap is removed as the target of a device context between the calls to BeginDraw and EndDraw.
  • Any of the IDeviceBitmap.Copy* methods are called with an IBitmap as either the source or destination.
Direct2D will only lock bitmaps that are not currently locked.
Resize(SizeInt32) will throw InvalidCallException if there are any outstanding references to the original bitmap associated with the device context.
Although the target can be a command list, it cannot be any other type of image. It cannot be an effect.