Table of Contents

Class BitmapRenderTarget

Namespace
SharpDX.DirectWrite
Assembly
SharpDX.Direct2D1.dll
[Guid("5e5a32a3-8dff-4773-9ff6-0696eab77267")]
public class BitmapRenderTarget : ComObject
Inheritance
BitmapRenderTarget
Derived

Constructors

BitmapRenderTarget(nint)

public BitmapRenderTarget(nint nativePtr)

Parameters

nativePtr nint

Properties

CurrentTransform

Gets or sets the transform that maps abstract coordinates to DIPs. By default this is the identity transform. Note that this is unrelated to the world transform of the underlying device context.

public RawMatrix3x2 CurrentTransform { get; set; }

Property Value

RawMatrix3x2

MemoryDC

Gets a handle to the memory device context.

public nint MemoryDC { get; }

Property Value

nint

Remarks

An application can use the device context to draw using GDI functions. An application can obtain the bitmap handle (nint) by calling GetCurrentObject. An application that wants information about the underlying bitmap, including a reference to the pixel data, can call GetObject to fill in a DIBSECTION structure. The bitmap is always a 32-bit top-down DIB.

Note that this method takes no parameters and returns an nint variable, not an SharpDX.Result.

memoryHdc = g_pBitmapRenderTarget->GetMemoryDC();

The nint returned here is still owned by the bitmap render targer object and should not be released or deleted by the client.

PixelsPerDip

Gets or sets the number of bitmap pixels per DIP.

public float PixelsPerDip { get; set; }

Property Value

float

Remarks

A DIP (device-independent pixel) is 1/96 inch. Therefore, this value is the number if pixels per inch divided by 96.

Size

Gets the dimensions of the target bitmap.

public Size2 Size { get; }

Property Value

Size2

Methods

DrawGlyphRun(float, float, MeasuringMode, GlyphRun, RenderingParams, RawColorBGRA)

Draws a run of glyphs to a bitmap target at the specified position.

public void DrawGlyphRun(float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, RenderingParams renderingParams, RawColorBGRA textColor)

Parameters

baselineOriginX float

The horizontal position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB.

baselineOriginY float

The vertical position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB.

measuringMode MeasuringMode

The measuring method for glyphs in the run, used with the other properties to determine the rendering mode.

glyphRun GlyphRun

The structure containing the properties of the glyph run.

renderingParams RenderingParams

The object that controls rendering behavior.

textColor RawColorBGRA

The foreground color of the text.

Remarks

You can use the IDWriteBitmapRenderTarget::DrawGlyphRun to render to a bitmap from a custom text renderer that you implement. The custom text renderer should call this method from within the SharpDX.DirectWrite.TextRenderer.DrawGlyphRun(System.IntPtr,System.Single,System.Single,SharpDX.DirectWrite.MeasuringMode,SharpDX.DirectWrite.GlyphRun,SharpDX.DirectWrite.GlyphRunDescription,SharpDX.ComObject) callback method as shown in the following code.

STDMETHODIMP GdiTextRenderer::DrawGlyphRun( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, DWRITE_MEASURING_MODE measuringMode, __in DWRITE_GLYPH_RUN const* glyphRun, __in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, IUnknown* clientDrawingEffect )	
           { HRESULT hr = S_OK; // Pass on the drawing call to the render target to do the real work. RECT dirtyRect = {0}; hr = pRenderTarget_->DrawGlyphRun( baselineOriginX, baselineOriginY, measuringMode, glyphRun, pRenderingParams_, RGB(0,200,255), &dirtyRect ); return hr;	
           }

The baselineOriginX, baslineOriginY, measuringMethod, and glyphRun parameters are provided (as arguments) when the callback method is invoked. The renderingParams, textColor and blackBoxRect are not. Default rendering params can be retrieved by using the SharpDX.DirectWrite.Factory.CreateMonitorRenderingParams(System.IntPtr,SharpDX.DirectWrite.RenderingParams@) method.

DrawGlyphRun(float, float, MeasuringMode, GlyphRun, RenderingParams, RawColorBGRA, out RawRectangle)

Draws a run of glyphs to a bitmap target at the specified position.

public void DrawGlyphRun(float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, RenderingParams renderingParams, RawColorBGRA textColor, out RawRectangle blackBoxRect)

Parameters

baselineOriginX float

The horizontal position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB.

baselineOriginY float

The vertical position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB.

measuringMode MeasuringMode

The measuring method for glyphs in the run, used with the other properties to determine the rendering mode.

glyphRun GlyphRun

The structure containing the properties of the glyph run.

renderingParams RenderingParams

The object that controls rendering behavior.

textColor RawColorBGRA

The foreground color of the text.

blackBoxRect RawRectangle

The optional rectangle that receives the bounding box (in pixels not DIPs) of all the pixels affected by drawing the glyph run. The black box rectangle may extend beyond the dimensions of the bitmap.

Remarks

You can use the DrawGlyphRun(float, float, MeasuringMode, GlyphRun, RenderingParams, RawColorBGRA, out RawRectangle) to render to a bitmap from a custom text renderer that you implement. The custom text renderer should call this method from within the DrawGlyphRun(object, float, float, MeasuringMode, GlyphRun, GlyphRunDescription, ComObject) callback method as shown in the following code.

STDMETHODIMP GdiTextRenderer::DrawGlyphRun( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, MeasuringMode measuringMode, __in GlyphRun const* glyphRun, __in GlyphRunDescription const* glyphRunDescription, SharpDX.ComObject* clientDrawingEffect )	
{ SharpDX.Result hr = SharpDX.Result.Ok; // Pass on the drawing call to the render target to do the real work. SharpDX.Mathematics.Interop.RawRectangle dirtyRect = {0}; hr = pRenderTarget_->DrawGlyphRun( baselineOriginX, baselineOriginY, measuringMode, glyphRun, pRenderingParams_, RGB(0,200,255), &dirtyRect ); return hr;	
}	

The baselineOriginX, baslineOriginY, measuringMethod, and glyphRun parameters are provided (as arguments) when the callback method is invoked. The renderingParams, textColor and blackBoxRect are not.

Default rendering params can be retrieved by using the SharpDX.DirectWrite.Factory.CreateMonitorRenderingParams(System.IntPtr,SharpDX.DirectWrite.RenderingParams) method.

Resize(int, int)

Resizes the bitmap.

public void Resize(int width, int height)

Parameters

width int

The new bitmap width, in pixels.

height int

The new bitmap height, in pixels.

Operators

explicit operator BitmapRenderTarget(nint)

public static explicit operator BitmapRenderTarget(nint nativePtr)

Parameters

nativePtr nint

Returns

BitmapRenderTarget