Table of Contents

Interface IDeviceContext

Namespace
PaintDotNet.Direct2D1
Assembly
PaintDotNet.Windows.dll

Represents a set of state and command buffers that are used to render to a target.
The device context can render to a target bitmap or a command list.
This interface corresponds to the follow Direct2D interfaces: ID2D1RenderTargetID2D1DeviceContextID2D1DeviceContext1ID2D1DeviceContext2ID2D1DeviceContext3ID2D1DeviceContext4ID2D1DeviceContext5ID2D1DeviceContext6

public interface IDeviceContext : IDirect2DResource, IFactoryProperty, IDeviceEffectFactory, IDeviceColorContextFactory, ILookupTable3DFactory, IObjectRef, IIsDisposed, IDisposable, IInternalImpl
Inherited Members
Extension Methods

Remarks

Any resource created from a device context can be shared with any other resource created from a device context when both contexts are created on the same IDevice.

Properties

AntialiasMode

Gets or sets the current antialiasing mode for drawing operations, excluding text and glyph drawing operations.

Device

Gets the device associated with a device context.

Dpi

Gets or sets the device context's dots-per-inch (DPI).

EffectBufferPrecision

The buffer precision used by default if the buffer precision is not otherwise specified by the effect or by the transform.

EffectTileSize

Gets or sets the tile allocation size to be used by the imaging effect renderer.

MaximumBitmapSize

Gets the maximum pixel size of any one bitmap dimension supported by the render target.

PixelFormat

Retrieves the pixel format and alpha mode of the current target.

PixelSize

Returns the size of the current target in device pixels.

PrimitiveBlend

Gets or sets the primitive blend used by the device context. The default is SourceOver.

Size

Returns the size of the current target in device-independent pixels.

TextAntialiasMode

Gets or sets the current antialiasing mode for text and glyph drawing operations.

Transform

Gets or sets the current transform of the device context. All subsequent drawing operations occur in the transformed space.

UnitMode

Gets or sets the mode that is being used to interpret values by the device context.

Methods

BeginDraw()

Initiates drawing on this render target.

BlendImage(IDeviceImage, BlendMode, Point2Float?, in RectFloat?, InterpolationMode)

Draws an image to the device context using the specified blend mode. Results are equivalent to using Direct2D's built-in Blend effect.

Clear(in ColorRgba128Float?)

Clears the drawing area to the specified color.

CreateBitmap(IBitmapSource, in BitmapProperties?)

Creates a Direct2D bitmap by copying an IBitmapSource.

CreateBitmap(SizeInt32, void*, int, in BitmapProperties)

Creates a bitmap that can be used as a target surface, for reading back to the CPU, or as a source for the DrawBitmap(IDeviceBitmap, in RectFloat?, float, InterpolationMode, in RectFloat?, in Matrix4x4Float?) and IBitmapBrush APIs. In addition, color context information can be passed to the bitmap.

CreateBitmapBrush(IDeviceBitmap, in BitmapBrushProperties?, in BrushProperties?)

Creates a bitmap brush, the input image is a Direct2D bitmap object.

CreateCommandList()

Creates an ICommandList object.

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

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

CreateFilledGeometryRealization(IGeometry, float?)

Creates a device-dependent representation of the fill of the geometry that can be subsequently rendered.

CreateGradientMesh(ReadOnlySpan<GradientMeshPatch>)

Creates a new IGradientMesh instance using the given array of patches.

CreateGradientStopCollection(ReadOnlySpan<GradientStop>, DeviceColorSpace, DeviceColorSpace, BufferPrecision, ExtendMode, ColorInterpolationMode)

Creates a gradient stop collection, enabling the gradient to contain color channels with values outside of [0,1] and also enabling rendering to a high-color render target with interpolation in sRGB space.

CreateGradientStopCollection(ReadOnlySpan<GradientStop>, GradientStopGamma, ExtendMode)

Creates an IGradientStopCollection from the specified array of GradientStop structures.

CreateImageBrush(IDeviceImage, in ImageBrushProperties, in BrushProperties?)

Creates an image brush. The input image can be any type of image, including a bitmap, effect, or a command list.

CreateInk(InkPoint)

Creates a new IDeviceInk object that starts at the given point.

CreateInkStyle(in InkStyleProperties)

Creates a new IDeviceInkStyle object, for use with ink rendering methods such as DrawImage(IDeviceImage, Point2Float?, in RectFloat?, InterpolationMode, CompositeMode).

CreateLayer(SizeFloat?)
CreateLinearGradientBrush(in LinearGradientBrushProperties, in BrushProperties?, IGradientStopCollection)

Creates an ILinearGradientBrush object for painting areas with a linear gradient.

CreateMesh()

Create a mesh that uses triangles to describe a shape.

CreateRadialGradientBrush(in RadialGradientBrushProperties, in BrushProperties?, IGradientStopCollection)

Creates an IRadialGradientBrush object that can be used to paint areas with a radial gradient.

CreateSharedBitmap(IDeviceBitmap, in SharedBitmapProperties?)

Creates an IDeviceBitmap whose data is shared (not copied) with another IDeviceBitmap.

CreateSharedBitmap(IBitmapLock, in SharedBitmapProperties?)

Creates an IDeviceBitmap whose data is shared (not copied) with an IBitmapLock.

CreateSolidColorBrush(ColorRgba128Float, in BrushProperties?)

Creates a new ISolidColorBrush that can be used to paint areas with a solid color.

CreateSpriteBatch()

Creates a new, empty sprite batch. After creating a sprite batch, use AddSprites(int, ReadOnlySpan<RectFloat>, ReadOnlySpan<RectInt32>, ReadOnlySpan<ColorRgba128Float>, ReadOnlySpan<Matrix3x2Float>) to add sprites to it, then use DrawSpriteBatch(ISpriteBatch, IDeviceBitmap, InterpolationMode, SpriteOptions) to draw it.

CreateStrokedGeometryRealization(IGeometry, float, IStrokeStyle?, float?)

Creates a device-dependent representation of the stroke of a geometry that can be subsequently rendered.

CreateSvgDocument(Stream?, SizeFloat)

Creates an SVG document from a stream.

CreateSvgGlyphStyle()

Creates an SVG glyph style object.

DrawBitmap(IDeviceBitmap, in RectFloat?, float, InterpolationMode, in RectFloat?, in Matrix4x4Float?)

Draws a bitmap to the render target.

DrawColorBitmapGlyphRun(GlyphImageFormats, Point2Float, in GlyphRun, TextMeasuringMode, ColorBitmapGlyphSnapOption)

Draws a color bitmap glyph run using one of the bitmap formats.

DrawEllipse(Ellipse, IDeviceBrush, float, IStrokeStyle?)

Draws the outline of the specified ellipse using the specified stroke style.

DrawGdiMetafile(IGdiMetafile, RectFloat, in RectFloat?)

Draws a metafile to the device context using the given source and destination rectangles.

DrawGdiMetafile(IGdiMetafile, Point2Float?)

Draw a metafile to the device context.

DrawGeometry(IGeometry, IDeviceBrush, float, IStrokeStyle?)

Draws the outline of the specified geometry using the specified stroke style.

DrawGeometryRealization(IGeometryRealization, IDeviceBrush)

Renders a given geometry realization to the target with the specified brush.

DrawGlyphRun(Point2Float, in GlyphRun, in GlyphRunDescription, IDeviceBrush, TextMeasuringMode)

Draws a series of glyphs to the device context.

DrawGradientMesh(IGradientMesh)

Renders a given gradient mesh to the target.

DrawImage(IDeviceImage, Point2Float?, in RectFloat?, InterpolationMode, CompositeMode)

Draws an image to the device context. The image can be any type of IDeviceImage, including an IDeviceEffect, IDeviceBitmap, or ICommandList.

DrawInk(IDeviceInk, IDeviceBrush, IDeviceInkStyle?)

Renders the given ink object using the given brush and ink style.

DrawLine(Point2Float, Point2Float, IDeviceBrush, float, IStrokeStyle?)

Draws a line between the specified points using the specified stroke style.

DrawRectangle(RectFloat, IDeviceBrush, float, IStrokeStyle?)

Draws the outline of a rectangle that has the specified dimensions and stroke style.

DrawRoundedRectangle(in RoundedRect, IDeviceBrush, float, IStrokeStyle?)

Draws the outline of the specified rounded rectangle using the specified stroke style.

DrawSpriteBatch(ISpriteBatch, IDeviceBitmap, InterpolationMode, SpriteOptions)

Renders all sprites in the given sprite batch to the device context using the specified drawing options.
NOTE: The antialiasing mode must be set to Aliased.

DrawSvgDocument(ISvgDocument)

Draws an SVG document.

DrawSvgGlyphRun(Point2Float, in GlyphRun, IDeviceBrush?, ISvgGlyphStyle?, int, TextMeasuringMode)

Draws a color glyph run that has the format of Svg.

DrawText(string, ITextFormat, RectFloat, IDeviceBrush, DrawTextOptions, TextMeasuringMode)

Draws the specified text using the format information provided by an ITextFormat object.

DrawText(string, ITextFormat, RectFloat, IDeviceBrush?, ISvgGlyphStyle?, int, DrawTextOptions, TextMeasuringMode)

Draws the text within the given layout rectangle.
By default, this method performs baseline snapping and renders color versions of glyphs in color fonts.

DrawTextLayout(Point2Float, ITextLayout, IDeviceBrush, DrawTextOptions)

Draws a text layout object. If the layout is not subsequently changed, this can be more efficient than DrawText when drawing the same layout repeatedly.

DrawTextLayout(Point2Float, ITextLayout, IDeviceBrush?, ISvgGlyphStyle?, int, DrawTextOptions)

Draws a text layout object. If the layout is not subsequently changed, this can be more efficient than DrawText when drawing the same layout repeatedly.

EndDraw()

Ends drawing operations on the render target and indicates the current error state.

FillEllipse(Ellipse, IDeviceBrush)

Paints the interior of the specified ellipse.

FillGeometry(IGeometry, IDeviceBrush, IDeviceBrush?)

Paints the interior of the specified geometry.

FillMesh(IDeviceMesh, IDeviceBrush)

Paints the interior of the specified mesh.
NOTE: The AntialiasMode must be set to Aliased.

FillOpacityMask(IDeviceBitmap, IDeviceBrush, in RectFloat?, in RectFloat?)

Fill using the alpha channel of the supplied opacity mask bitmap. The brush opacity will be modulated by the mask.
NOTE: The antialiasing mode must be set to Aliased.

FillRectangle(RectFloat, IDeviceBrush)

Paints the interior of the specified rectangle.

FillRoundedRectangle(in RoundedRect, IDeviceBrush)

Paints the interior of the specified rounded rectangle.

Flush()

Executes all pending drawing commands.

GetColorBitmapGlyphImage(GlyphImageFormats, Point2Float, IFontFace, float, ushort, bool, in Matrix3x2Float?, Vector2Float, out Matrix3x2Float)

Retrieves an image of the color bitmap glyph from the color glyph cache. If the cache does not already contain the requested resource, it will be created. This method may be used to extend the lifetime of a glyph image even after it is evicted from the color glyph cache.

GetEffectInvalidRectangles(IDeviceEffect)

Gets the invalid rectangles that have accumulated since the last time the effect was drawn and EndDraw() was then called on the device context.

GetEffectRequiredInputRectangles(IDeviceEffect, in RectFloat?, ReadOnlySpan<EffectInputDescription>)

Returns the input rectangles that are required to be supplied by the caller to produce the given output rectangle.

GetGlyphRunWorldBounds(Point2Float, in GlyphRun, TextMeasuringMode)

Gets the world-space bounds in DIPs of the glyph run using the device context DPI.

GetGradientMeshWorldBounds(IGradientMesh)

Returns the world bounds of a given gradient mesh.

GetImageLocalBounds(IDeviceImage)

Gets the bounds of an image without the world transform of the context applied.

GetImageWorldBounds(IDeviceImage)

Gets the bounds of an image with the world transform of the context applied.

GetSvgGlyphImage(Point2Float, IFontFace, float, ushort, bool, in Matrix3x2Float?, IDeviceBrush?, ISvgGlyphStyle?, int, out Matrix3x2Float)

Retrieves an image of the SVG glyph from the color glyph cache. If the cache does not already contain the requested resource, it will be created. This method may be used to extend the lifetime of a glyph image even after it is evicted from the color glyph cache.

GetTarget()

Gets the target currently associated with the device context.

GetTextRenderingParameters()

Retrieves the device context's current text rendering options.

InvalidateEffectInputRectangle(IDeviceEffect, int, RectFloat)

This indicates that a portion of an effect's input is invalid. This method can be called many times.

You can use this method to propagate invalid rectangles through an effect graph. You can query Direct2D using the GetEffectInvalidRectangles(IDeviceEffect) method.

NOTE: Direct2D does not automatically use these invalid rectangles to reduce the region of an effect that is rendered.
You can also use this method to invalidate caches that have accumulated while rendering effects that have the Cached property set to true.

IsBufferPrecisionSupported(BufferPrecision)

Indicates whether the buffer precision is supported by the underlying Direct2D IDevice.

IsDxgiFormatSupported(DxgiFormat)

Indicates whether the format is supported by the device context. The formats supported are usually determined by the underlying hardware.

IsSupported(in DeviceContextProperties)

Indicates whether the device context supports the specified properties.

PopAxisAlignedClip()

Removes the last axis-aligned clip from the render target. After this method is called, the clip is no longer applied to subsequent drawing operations.

PopLayer()

Stops redirecting drawing operations to the layer that is specified by the last PushLayer(in LayerParameters, IDeviceLayer?) call.
See Direct2D Layers Overview for more information.

PushAxisAlignedClip(RectFloat, AntialiasMode)

Specifies a rectangle to which all subsequent drawing operations are clipped.

PushLayer(in LayerParameters, IDeviceLayer?)

Push a layer onto the clip and layer stack of the device context. The layer will receive all subequent drawing operations until PopLayer() is called.
See Direct2D Layers Overview for more information.

RestoreDrawingState(IDrawingStateBlock)

Sets the render target's drawing state to that of the specified IDrawingStateBlock.

SaveDrawingState(IDrawingStateBlock)

Saves the current drawing state to the specified IDrawingStateBlock.

SetTarget(IDeviceImage?)

The bitmap or command list to which the Direct2D device context will now render.

SetTextRenderingParameters(ITextRenderingParameters?)

Specifies text rendering options to be applied to all subsequent text and glyph drawing operations.