Description
The CreateFromSvgString
method is a static method of the Bitmap
class in the Sandbox namespace. It allows you to create a Bitmap
object from an SVG string. This method provides options to specify the dimensions, scale, offset, and rotation of the resulting bitmap.
Usage
To use the CreateFromSvgString
method, you need to provide the SVG content as a string. Optionally, you can specify the width and height of the bitmap. If these are not provided, the method will use the default dimensions. You can also specify a scale and offset using Vector2
objects, and a rotation angle in degrees.
Here is the method signature:
public static Bitmap CreateFromSvgString(
string svgContents,
int? width = null,
int? height = null,
Vector2? scale = null,
Vector2? offset = null,
float? rotation = null
)
Example
// Example of creating a Bitmap from an SVG string
string svgData = "<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'><circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' /></svg>";
// Create a Bitmap from the SVG string
Bitmap bitmap = Bitmap.CreateFromSvgString(svgData, width: 200, height: 200, scale: new Vector2(1.5f, 1.5f), offset: new Vector2(10, 10), rotation: 45.0f);
// Use the bitmap as needed, for example, rendering it in a UI or saving it to a file.