Method SetTarget
- Namespace
- PaintDotNet.Direct2D1
- Assembly
- PaintDotNet.Windows.dll
SetTarget(IDeviceImage?)
The bitmap or command list to which the Direct2D device context will now render.
void SetTarget(IDeviceImage? target)
Parameters
target
IDeviceImageThe bitmap or command list to which the Direct2D device context will render.
Remarks
The target can be changed at any time, including while the context is drawing.
The target can be either a bitmap created with the D2D1_BITMAP_OPTIONS_TARGET flag, or it can be a command list. Other kinds
of images cannot be set as a target. For example, you cannot set an effect as target. If the target is not valid the context
will enter the InvalidTarget error state.
You cannot use SetTarget to render to a bitmap/command list from multiple device contexts simultaneously. An image is considered
“being rendered to” if it has ever been set on a device context within a BeginDraw/EndDraw timespan. If an attempt is made to
render to an image through multiple device contexts, all subsequent device contexts after the first will enter an error state.
Callers wishing to attach an image to a second device context should first call EndDraw on the first device context.
Note: Changing the target does not change the bitmap that an HWND device context presents from, nor does it change the
bitmap that a DC device context blts to/from.
This API makes it easy for an application to use a bitmap as a source (like in DrawBitmap) and as a destination at the same time.
Attempting to use a bitmap as a source on the same device context to which it is bound as a target will put the device context
into the BitmapBoundAsTarget error state.
It is acceptable to have a bitmap bound as a target bitmap on multiple render targets at once. Applications that do this must
properly synchronize rendering with Flush() or EndDraw().
You can change the target at any time, including while the context is drawing.
You can set the target to null, in which case drawing calls will put the device context into an error state with WrongState.
Calling SetTarget with a null target does not restore the original target bitmap to the device context.
If the device context has an outstanding HDC, the context will enter the WrongState error state. The target will not be changed.
If the bitmap and the device context are not in the same resource domain, the context will enter an error state. The target will
not be changed.
PixelSize returns the size of the current target bitmap (or 0, 0) if there is no bitmap bound). Size
returns the pixel size of the current bitmap scaled by the DPI of the render target. SetTarget does not affect the DPI of the
render target.
PixelFormat returns the pixel format of the current target bitmap, or Unknown if
there is none.
CopyFromDeviceContext(Point2Int32?, IDeviceContext, in RectInt32?) copies from the currently bound target bitmap.