Show / Hide Table of Contents

Method CreateSwatchAsync

CreateSwatchAsync(double)

Creates a swatch image of this symbol using the default size and a transparent background.

Declaration
public virtual Task<RuntimeImage?> CreateSwatchAsync(double dpi = 96)
Parameters
Type Name Description
double dpi

Pixel density (dots per inch) to use when creating the swatch. Default is 96.

Returns
Type Description
Task<RuntimeImage>

An RuntimeImage is returned asynchronously by the task. A null is returned if an error occurs or if the symbol is specific to 3D, such as ModelSceneSymbol, MultilayerMeshSymbol, or MultilayerPointSymbol that includes a ModelSymbolLayer.

Remarks

Dimensions of the created image will be at least 20x20 pixels (at 96 dpi), and may be larger depending on symbol size. Minimum swatch size scales with dpi. Note that if the swatch is created without an explicit size or geometry, an accurate representation of symbol patterns might not be captured in the output image.

Applies to

Platforms and versions
TargetVersions
.NET Standard 2.0100.3 - 200.8
.NET100.13 - 300.0
.NET Windows100.13 - 300.0
.NET Android200.0 - 300.0
.NET iOS200.0 - 300.0
.NET Framework100.0 - 200.8
Xamarin.Android100.0 - 100.15
Xamarin.iOS100.0 - 100.15
UWP100.0 - 200.8

CreateSwatchAsync(Color, double)

Creates a swatch image of this symbol, using the default sizing and a transparent background.

Declaration
public Task<RuntimeImage?> CreateSwatchAsync(Color backgroundColor, double dpi = 96)
Parameters
Type Name Description
Color backgroundColor

The image background color.

double dpi

Pixel density (dots per inch) to use when creating the swatch. Default is 96.

Returns
Type Description
Task<RuntimeImage>

An RuntimeImage is returned asynchronously by the task. A null is returned if an error occurs or if the symbol is specific to 3D, such as ModelSceneSymbol, MultilayerMeshSymbol, or MultilayerPointSymbol that includes a ModelSymbolLayer.

Remarks

Dimensions of the created image will be at least 20x20 pixels (at 96 dpi), and may be larger depending on symbol size. Minimum swatch size scales with dpi. Note that if the swatch is created without an explicit size or geometry, an accurate representation of symbol patterns might not be captured in the output image.

Applies to

Platforms and versions
TargetVersions
.NET Standard 2.0100.3 - 200.8
.NET100.13 - 300.0
.NET Windows100.13 - 300.0
.NET Android200.2 - 300.0
.NET iOS200.0 - 300.0
.NET Framework100.3 - 200.8
Xamarin.Android100.0 - 100.14
Xamarin.iOS100.0 - 100.15
UWP100.3 - 200.8

CreateSwatchAsync(int, int, float, Color, Geometry)

Creates a swatch image of this symbol, with the specified image size, dpi, background color, and geometry.

Declaration
public Task<RuntimeImage?> CreateSwatchAsync(int widthPixels, int heightPixels, float dpi, Color backgroundColor, Geometry geometry)
Parameters
Type Name Description
int widthPixels

The width of the swatch in device-independent pixels (DIPs).

int heightPixels

The height of the swatch in device-independent pixels (DIPs).

float dpi

Pixel density (dots per inch) to use when creating the swatch. This value is used to scale symbology when rendering the swatch. The value should be set appropriately in order to render swatches at the correct scale for a given display.

note

Picture marker symbols without a set width or height are not scaled by screen scale, as unset width and height are taken to mean "render at native pixel scale".

Color backgroundColor

The image background color.

Geometry geometry

The custom geometry of the symbol to be drawn in the swatch image. The specified geometry is in DIPs, with the point {0,0} located at the center of the swatch image. The X-axis increases towards the right side of the swatch image. The Y-axis increases towards the top of the swatch image. For example: when creating a swatch for a MarkerSymbol, specifying a geometry of {10,10} will draw the marker 10 DIPs up and to the right of the center of the swatch. The geometry type (Point, Polyline, Polygon) should correspond to the symbol type (MarkerSymbol, LineSymbol, FillSymbol). The geometry's spatial reference is ignored.

Returns
Type Description
Task<RuntimeImage>

An RuntimeImage is returned asynchronously by the task. A null is returned if an error occurs or if the symbol is specific to 3D, such as ModelSceneSymbol, MultilayerMeshSymbol, or MultilayerPointSymbol that includes a ModelSymbolLayer.

Remarks

widthPixels and heightPixels may need to be adjusted if dpi is different from its default value of 96. This method does not scale the symbol in order to fit or fill the entire image. The symbol is rendered at its actual size, which may result in some cropping or padding.

The geometry should be specified DIPs, with the point {0,0} located at the centerpoint of the swatch image. The X-axis increases towards the right-hand side of the swatch image. The Y-axis increases towards the top of the swatch image. Geometry type should correspond to symbol type: MapPoint for MarkerSymbol, Polyline for LineSymbol, and Polygon for FillSymbol. Given geometry's spatial reference is ignored.

Applies to

Platforms and versions
TargetVersions
.NET Standard 2.0100.3 - 200.8
.NET100.13 - 300.0
.NET Windows100.13 - 300.0
.NET Android200.2 - 300.0
.NET iOS200.0 - 300.0
.NET Framework100.3 - 200.8
Xamarin.Android100.0 - 100.14
Xamarin.iOS100.0 - 100.15
UWP100.3 - 200.8

CreateSwatchAsync(int, int, double, Color)

Creates a swatch image of this symbol, scaled to fit the specified dimensions.

Declaration
public Task<RuntimeImage?> CreateSwatchAsync(int widthPixels, int heightPixels, double dpi, Color backgroundColor)
Parameters
Type Name Description
int widthPixels

The width of the swatch in device-independent pixels (DIPs).

int heightPixels

The height of the swatch in device-independent pixels (DIPs).

double dpi

Pixel density (dots per inch) to use when creating the swatch.

Color backgroundColor

The background color of the image.

Returns
Type Description
Task<RuntimeImage>

An RuntimeImage is returned asynchronously by the task. A null is returned if an error occurs or if the symbol is specific to 3D, such as ModelSceneSymbol, MultilayerMeshSymbol, or MultilayerPointSymbol that includes a ModelSymbolLayer.

Remarks

This method will scale the symbol up or down in order to fill the entire image. Symbol's aspect ratio will be preserved.

Applies to

Platforms and versions
TargetVersions
.NET Standard 2.0100.3 - 200.8
.NET100.13 - 300.0
.NET Windows100.13 - 300.0
.NET Android200.2 - 300.0
.NET iOS200.0 - 300.0
.NET Framework100.3 - 200.8
Xamarin.Android100.1 - 100.14
Xamarin.iOS100.1 - 100.15
UWP100.3 - 200.8
In this article
Provide feedback
Back to top Copyright © 2025 Esri.