Click or drag to resize
AB4D logo

BitmapRenderingRenderToBitmap Method (FrameworkElement, Int32, Int32, Boolean, Int32, Brush, Int32, RenderTargetBitmap)

Renders FrameworkElement specified with objectToRender to bitmap. It is possible to specify custom bitmap width and height (when customWidth and customHeight are bigger than 0). When antialiasingLevel is bigger than 1, the bitmap is rendered into bigger image and than scaled down to create an antialiasing effect.

Namespace:  Ab3d.Utilities
Assembly:  Ab3d.PowerToys (in Ab3d.PowerToys.dll) Version: 10.2.8348.1045
Syntax
C#
public static BitmapSource RenderToBitmap(
	FrameworkElement objectToRender,
	int customWidth,
	int customHeight,
	bool scaleToFill = true,
	int antialiasingLevel = 0,
	Brush backgroundBrush = null,
	int dpi = 96,
	RenderTargetBitmap renderTargetBitmapToReuse = null
)

Parameters

objectToRender
Type: System.WindowsFrameworkElement
FrameworkElement to render
customWidth
Type: SystemInt32
when bigger than 0 it specifies the target bitmap width; when zero the width of objectToRender will be used
customHeight
Type: SystemInt32
when bigger than 0 it specifies the target bitmap height; when zero the height of objectToRender will be used
scaleToFill (Optional)
Type: SystemBoolean
when true the object will be scaled to fill the target bitmap (when source and target aspect ratio is not the same)
antialiasingLevel (Optional)
Type: SystemInt32
when bigger than 1, the bitmap will be rendered into bigger image and than scaled down to create an antialiasing effect. The antialiasingLevel defines the scale factor of the intermediate bitmap. Max value is 8. When antialiasingLevel value is bigger then 1, then a TransformedBitmap object type is returned, otherwise a RenderTargetBitmap object type is returned.
backgroundBrush (Optional)
Type: System.Windows.MediaBrush
brush used for background or null to have no background. Default value is null.
dpi (Optional)
Type: SystemInt32
DPI setting for the rendered bitmap. Default value is 96
renderTargetBitmapToReuse (Optional)
Type: System.Windows.Media.ImagingRenderTargetBitmap
when not null and when its size is the same as the size defined by the customWidth and customHeight, then the renderTargetBitmapToReuse is cleared and used again to improve memory usage.

Return Value

Type: BitmapSource
BitmapSource
See Also