Class DeviceContext
[Guid("e8f7fe7a-191c-466d-ad95-975678bda998")]
public class DeviceContext : RenderTarget
- Inheritance
-
DeviceContext
- Derived
- Inherited Members
Constructors
DeviceContext(Surface)
Initializes a new instance of the DeviceContext class.
public DeviceContext(Surface surface)
Parameters
surface
SurfaceThe surface.
DeviceContext(Surface, CreationProperties)
Initializes a new instance of the Device class.
public DeviceContext(Surface surface, CreationProperties creationProperties)
Parameters
surface
SurfaceThe surface.
creationProperties
CreationPropertiesThe creation properties.
DeviceContext(Device, DeviceContextOptions)
Initializes a new instance of the DeviceContext class using an existing Device.
public DeviceContext(Device device, DeviceContextOptions options)
Parameters
device
DeviceThe device.
options
DeviceContextOptionsThe options to be applied to the created device context.
Remarks
The new device context will not have a selected target bitmap. The caller must create and select a bitmap as the target surface of the context.
DeviceContext(nint)
public DeviceContext(nint nativePtr)
Parameters
nativePtr
nint
Properties
Device
Gets the device associated with a device context.
public Device Device { get; }
Property Value
Remarks
The application can retrieve the device even if it is created from an earlier render target code-path. The application must use an DeviceContext interface and then call GetDevice. Some functionality for controlling all of the resources for a set of device contexts is maintained only on an Device object.
PrimitiveBlend
Returns or sets the currently set primitive blend used by the device context.
public PrimitiveBlend PrimitiveBlend { get; set; }
Property Value
RenderingControls
Gets or sets the rendering controls that have been applied to the context.
public RenderingControls RenderingControls { get; set; }
Property Value
Target
Gets or sets the target currently associated with the device context.
public Image Target { get; set; }
Property Value
Remarks
If a target is not associated with the device context, target will contain null
when the methods returns.
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:
- CreateHwndRenderTarget
- CreateDxgiSurfaceRenderTarget
- CreateWicBitmapRenderTarget
- CreateDCRenderTarget
- CreateCompatibleRenderTarget
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 RenderTarget methods.
CreateDxgiSurfaceRenderTarget will create a bitmap that is usable as a bitmap source if the DXGI surface is bindable as a shader resource view.
CreateCompatibleRenderTarget will always create bitmaps that are usable as a bitmap source.
ID2D1RenderTarget::BeginDraw will copy from the nint to the original bitmap associated with it. ID2D1RenderTarget::EndDraw will copy from the original bitmap to the nint.
Bitmap objects will be locked in the following circumstances:
- BeginDraw has been called and the currently selected target bitmap is a WIC bitmap.
- A WIC bitmap is set as the target of a device context after BeginDraw has been called and before EndDraw has been called.
- Any of the ID2D1Bitmap::Copy* methods are called with a WIC bitmap as either the source or destination.
Bitmap objects will be unlocked in the following circumstances:
- EndDraw is called and the currently selected target bitmap is a WIC bitmap.
- A WIC bitmap is removed as the target of a device context between the calls to BeginDraw and EndDraw.
- Any of the ID2D1Bitmap::Copy* methods are called with a WIC bitmap as either the source or destination.
Direct2D will only lock bitmaps that are not currently locked.
Calling QueryInterface for GdiInteropRenderTarget will always succeed. ID2D1GdiInteropRenderTarget::GetDC will return a device context corresponding to the currently bound target bitmap. GetDC will fail if the target bitmap was not created with the GDI_COMPATIBLE flag set.
ID2D1HwndRenderTarget::Resize will return
Although the target can be a command list, it cannot be any other type of image. It cannot be the output image of an effect.
UnitMode
Gets or sets the mode that is being used to interpret values by the device context.
public UnitMode UnitMode { get; set; }
Property Value
Methods
DrawBitmap(Bitmap, RawRectangleF?, float, InterpolationMode, RawRectangleF?, RawMatrix?)
Draws a bitmap to the render target.
public void DrawBitmap(Bitmap bitmap, RawRectangleF? destinationRectangle, float opacity, InterpolationMode interpolationMode, RawRectangleF? sourceRectangle, RawMatrix? erspectiveTransformRef)
Parameters
bitmap
BitmapThe bitmap to draw.
destinationRectangle
RawRectangleF?The destination rectangle. The default is the size of the bitmap and the location is the upper left corner of the render target.
opacity
floatThe opacity of the bitmap.
interpolationMode
InterpolationModeThe interpolation mode to use.
sourceRectangle
RawRectangleF?An optional source rectangle.
erspectiveTransformRef
RawMatrix?An optional perspective transform.
Remarks
The destinationRectangle parameter defines the rectangle in the target where the bitmap will appear (in device-independent pixels (DIPs)). This is affected by the currently set transform and the perspective transform, if set. If null
is specified, then the destination rectangle is (left=0, top=0, right = width(sourceRectangle), bottom = height(sourceRectangle)).
The sourceRectangle parameter defines the sub-rectangle of the source bitmap (in DIPs). DrawBitmap will clip this rectangle to the size of the source bitmap, thus making it impossible to sample outside of the bitmap. If null
is specified, then the source rectangle is taken to be the size of the source bitmap.
If you specify perspectiveTransform it is applied to the rect in addition to the transform set on the render target.
DrawBitmap(Bitmap, float, InterpolationMode)
Draws the bitmap.
public void DrawBitmap(Bitmap bitmap, float opacity, InterpolationMode interpolationMode)
Parameters
bitmap
BitmapThe bitmap.
opacity
floatThe opacity.
interpolationMode
InterpolationModeThe interpolation mode.
DrawBitmap(Bitmap, float, InterpolationMode, RawMatrix)
Draws the bitmap.
public void DrawBitmap(Bitmap bitmap, float opacity, InterpolationMode interpolationMode, RawMatrix perspectiveTransformRef)
Parameters
bitmap
BitmapThe bitmap.
opacity
floatThe opacity.
interpolationMode
InterpolationModeThe interpolation mode.
perspectiveTransformRef
RawMatrixThe perspective transform ref.
DrawBitmap(Bitmap, float, InterpolationMode, RawRectangleF, RawMatrix)
Draws the bitmap.
public void DrawBitmap(Bitmap bitmap, float opacity, InterpolationMode interpolationMode, RawRectangleF sourceRectangle, RawMatrix perspectiveTransformRef)
Parameters
bitmap
BitmapThe bitmap.
opacity
floatThe opacity.
interpolationMode
InterpolationModeThe interpolation mode.
sourceRectangle
RawRectangleFThe source rectangle.
perspectiveTransformRef
RawMatrixThe perspective transform ref.
DrawGdiMetafile(GdiMetafile, RawVector2?)
Draw a metafile to the device context.
public void DrawGdiMetafile(GdiMetafile gdiMetafile, RawVector2? targetOffset)
Parameters
gdiMetafile
GdiMetafileThe metafile to draw.
targetOffset
RawVector2?The offset from the upper left corner of the render target.
DrawGlyphRun(RawVector2, GlyphRun, GlyphRunDescription, Brush, MeasuringMode)
Draws a series of glyphs to the device context.
public void DrawGlyphRun(RawVector2 baselineOrigin, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, Brush foregroundBrush, MeasuringMode measuringMode)
Parameters
baselineOrigin
RawVector2Origin of first glyph in the series.
glyphRun
GlyphRunThe glyphs to render.
glyphRunDescription
GlyphRunDescriptionSupplementary glyph series information.
foregroundBrush
BrushThe brush that defines the text color.
measuringMode
MeasuringModeThe measuring mode of the glyph series, used to determine the advances and offsets. The default value is DWRITE_MEASURING_MODE_NATURAL.
Remarks
The glyphRunDescription is ignored when rendering, but can be useful for printing and serialization of rendering commands, such as to an XPS or SVG file. This extends ID2D1RenderTarget::DrawGlyphRun, which lacked the glyph run description.
DrawImage(Effect, InterpolationMode, CompositeMode)
No documentation.
public void DrawImage(Effect effect, InterpolationMode interpolationMode = InterpolationMode.Linear, CompositeMode compositeMode = CompositeMode.SourceOver)
Parameters
effect
EffectNo documentation.
interpolationMode
InterpolationModeNo documentation.
compositeMode
CompositeModeNo documentation.
DrawImage(Effect, RawVector2, InterpolationMode, CompositeMode)
No documentation.
public void DrawImage(Effect effect, RawVector2 targetOffset, InterpolationMode interpolationMode = InterpolationMode.Linear, CompositeMode compositeMode = CompositeMode.SourceOver)
Parameters
effect
EffectNo documentation.
targetOffset
RawVector2No documentation.
interpolationMode
InterpolationModeNo documentation.
compositeMode
CompositeModeNo documentation.
DrawImage(Image, InterpolationMode, CompositeMode)
No documentation.
public void DrawImage(Image image, InterpolationMode interpolationMode = InterpolationMode.Linear, CompositeMode compositeMode = CompositeMode.SourceOver)
Parameters
image
ImageNo documentation.
interpolationMode
InterpolationModeNo documentation.
compositeMode
CompositeModeNo documentation.
DrawImage(Image, RawVector2, InterpolationMode, CompositeMode)
No documentation.
public void DrawImage(Image image, RawVector2 targetOffset, InterpolationMode interpolationMode = InterpolationMode.Linear, CompositeMode compositeMode = CompositeMode.SourceOver)
Parameters
image
ImageNo documentation.
targetOffset
RawVector2No documentation.
interpolationMode
InterpolationModeNo documentation.
compositeMode
CompositeModeNo documentation.
DrawImage(Image, RawVector2?, RawRectangleF?, InterpolationMode, CompositeMode)
A command list cannot reference effects which are part of effect graphs that consume the command list.
public void DrawImage(Image image, RawVector2? targetOffset, RawRectangleF? imageRectangle, InterpolationMode interpolationMode, CompositeMode compositeMode)
Parameters
image
ImageNo documentation.
targetOffset
RawVector2?No documentation.
imageRectangle
RawRectangleF?No documentation.
interpolationMode
InterpolationModeNo documentation.
compositeMode
CompositeModeNo documentation.
FillOpacityMask(Bitmap, Brush)
No documentation.
public void FillOpacityMask(Bitmap opacityMask, Brush brush)
Parameters
FillOpacityMask(Bitmap, Brush, RawRectangleF?, RawRectangleF?)
Fill using the alpha channel of the supplied opacity mask bitmap. The brush opacity will be modulated by the mask. The render target antialiasing mode must be set to aliased.
public void FillOpacityMask(Bitmap opacityMask, Brush brush, RawRectangleF? destinationRectangle, RawRectangleF? sourceRectangle)
Parameters
opacityMask
BitmapThe bitmap that acts as the opacity mask
brush
BrushThe brush to use for filling the primitive.
destinationRectangle
RawRectangleF?The destination rectangle to output to in the render target
sourceRectangle
RawRectangleF?The source rectangle from the opacity mask bitmap.
GetEffectInvalidRectangles(Effect)
Gets the effect invalid rectangles.
public RawRectangleF[] GetEffectInvalidRectangles(Effect effect)
Parameters
effect
EffectThe effect.
Returns
- RawRectangleF[]
GetEffectRequiredInputRectangles(Effect, EffectInputDescription[])
Gets the effect required input rectangles.
public RawRectangleF[] GetEffectRequiredInputRectangles(Effect renderEffect, EffectInputDescription[] inputDescriptions)
Parameters
renderEffect
EffectThe render effect.
inputDescriptions
EffectInputDescription[]The input descriptions.
Returns
- RawRectangleF[]
GetEffectRequiredInputRectangles(Effect, RawRectangleF, EffectInputDescription[])
Gets the effect required input rectangles.
public RawRectangleF[] GetEffectRequiredInputRectangles(Effect renderEffect, RawRectangleF renderImageRectangle, EffectInputDescription[] inputDescriptions)
Parameters
renderEffect
EffectThe render effect.
renderImageRectangle
RawRectangleFThe render image rectangle.
inputDescriptions
EffectInputDescription[]The input descriptions.
Returns
- RawRectangleF[]
GetGlyphRunWorldBounds(RawVector2, GlyphRun, MeasuringMode)
Gets the world-space bounds in DIPs of the glyph run using the device context DPI.
public RawRectangleF GetGlyphRunWorldBounds(RawVector2 baselineOrigin, GlyphRun glyphRun, MeasuringMode measuringMode)
Parameters
baselineOrigin
RawVector2The origin of the baseline for the glyph run.
glyphRun
GlyphRunThe glyph run to render.
measuringMode
MeasuringModeThe DirectWrite measuring mode that indicates how glyph metrics are used to measure text when it is formatted.
Returns
- RawRectangleF
The bounds of the glyph run in DIPs and in world space.
Remarks
The image bounds reflect the current DPI, unit mode, and world transform of the context.
GetImageLocalBounds(Image)
Gets the bounds of an image without the world transform of the context applied.
public RawRectangleF GetImageLocalBounds(Image image)
Parameters
image
ImageThe image whose bounds will be calculated.
Returns
- RawRectangleF
When this method returns, contains a reference to the bounds of the image in device independent pixels (DIPs) and in local space.
Remarks
The image bounds don't include multiplication by the world transform. They do reflect the current DPI, unit mode, and interpolation mode of the context. To get the bounds that include the world transform, use ID2D1DeviceContext::GetImageWorldBounds.
The returned bounds reflect which pixels would be impacted by calling DrawImage with a target offset of (0,0) and an identity world transform matrix. They do not reflect the current clip rectangle set on the device context or the extent of the context's current target image.
GetImageWorldBounds(Image)
Gets the bounds of an image with the world transform of the context applied.
public RawRectangleF GetImageWorldBounds(Image image)
Parameters
image
ImageThe image whose bounds will be calculated.
Returns
- RawRectangleF
When this method returns, contains a reference to the bounds of the image in device independent pixels (DIPs).
Remarks
The image bounds reflect the current DPI, unit mode, and world transform of the context. To get bounds which don't include the world transform, use ID2D1DeviceContext::GetImageLocalBounds.
The returned bounds reflect which pixels would be impacted by calling DrawImage with the same image and a target offset of (0,0). They do not reflect the current clip rectangle set on the device context or the extent of the context?s current target image.
InvalidateEffectInputRectangle(Effect, int, RawRectangleF)
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 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 D2D1_PROPERTY_CACHED property set to true.
public void InvalidateEffectInputRectangle(Effect effect, int input, RawRectangleF inputRectangle)
Parameters
effect
EffectNo documentation.
input
intNo documentation.
inputRectangle
RawRectangleFNo documentation.
IsBufferPrecisionSupported(BufferPrecision)
Indicates whether the buffer precision is supported by the underlying Direct3D device.
public RawBool IsBufferPrecisionSupported(BufferPrecision bufferPrecision)
Parameters
bufferPrecision
BufferPrecisionNo documentation.
Returns
- RawBool
Returns TRUE if the buffer precision is supported. Returns SharpDX.Result.False if the buffer precision is not supported.
IsDxgiFormatSupported(Format)
Indicates whether the format is supported by the device context. The formats supported are usually determined by the underlying hardware.
public RawBool IsDxgiFormatSupported(Format format)
Parameters
format
FormatThe DXGI format to check.
Returns
- RawBool
Returns TRUE if the format is supported. Returns SharpDX.Result.False if the format is not supported.
Remarks
You can use supported formats in the PixelFormat structure to create bitmaps and render targets. Direct2D doesn't support all DXGI formats, even though they may have some level of Direct3D support by the hardware.
PushLayer(LayerParameters1, Layer)
No documentation.
public void PushLayer(LayerParameters1 layerParameters, Layer layer)
Parameters
layerParameters
LayerParameters1No documentation.
layer
LayerNo documentation.
PushLayer(ref LayerParameters1, Layer)
Push a layer onto the clip and layer stack of the device context.
public void PushLayer(ref LayerParameters1 layerParameters, Layer layer)
Parameters
layerParameters
LayerParameters1The parameters that defines the layer.
layer
LayerThe layer resource to push on the device context that receives subsequent drawing operations.
Note??If a layer is not specified, Direct2D manages the layer resource automatically. ?
Operators
explicit operator DeviceContext(nint)
public static explicit operator DeviceContext(nint nativePtr)
Parameters
nativePtr
nint