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.
Parameters:
svgContents
(string): The SVG content to be converted into a bitmap.
width
(int?): The desired width of the bitmap. If null, the default width is used.
height
(int?): The desired height of the bitmap. If null, the default height is used.
scale
(Vector2?): The scale factor for the bitmap. If null, no scaling is applied.
offset
(Vector2?): The offset to apply to the bitmap. If null, no offset is applied.
rotation
(float?): The rotation angle in degrees. If null, no rotation is applied.
Example
// Example of creating a Bitmap from an SVG string
string svgContent = "<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(svgContent, 100, 100, new Vector2(1.0f, 1.0f), new Vector2(0.0f, 0.0f), 0.0f);
// Use the bitmap as needed
// For example, convert it to a texture
Texture texture = bitmap.ToTexture(false);