ImageSVG component.
ImageSVG Component
TheImageSVG component renders SVG graphics on the canvas.
Props
| Name | Type | Description |
|---|---|---|
| svg | SkSVG | SVG image instance loaded with useSVG |
| x | number | Optional x coordinate of the SVG container |
| y | number | Optional y coordinate of the SVG container |
| width | number | Width when root SVG uses relative units |
| height | number | Height when root SVG uses relative units |
Basic Example
Loading SVG Files
From Bundle
Load SVG files from your JavaScript bundle:From Network
Load SVG files from a URL:From String
Create SVG from inline strings:From Data
Create from encoded data:Positioning and Sizing
Absolute Units
If the SVG has absolute dimensions, the width/height props have no effect:Relative Units
For SVGs with relative dimensions (percentages), use width/height:Positioning
Working with Text in SVG
BothSkia.SVG.MakeFromData and Skia.SVG.MakeFromString accept an optional font manager for custom fonts:
SVG Instance Methods
TheSkSVG instance provides dimension methods:
Applying Effects
TheImageSVG component doesn’t follow standard painting rules. To apply effects, use the layer property:
Color Filter
Opacity
Platform Differences
Web Platform
On Web, the Current Transformation Matrix (CTM) is not applied toImageSVG because it uses browser SVG rendering:
Native Platforms
On iOS and Android, transformations work as expected:Common Patterns
Responsive SVG
Centered SVG
SVG Grid
Animated SVG
Performance Tips
- Cache loaded SVGs with
useSVG - Use appropriate dimensions to avoid unnecessary scaling
- Consider rasterizing complex SVGs to images
- Limit the number of SVGs rendered simultaneously
- Preload SVGs when possible
Troubleshooting
SVG Not Rendering
- Check that the SVG loaded successfully (not
null) - Verify the SVG file is valid
- Ensure width/height are provided for relative-sized SVGs
Font Issues
- Provide a font manager when SVG contains text
- Ensure fonts are properly loaded with
useFonts - Check font family names match SVG requirements
Transform Issues on Web
- Use
Groupcomponent for transformations on Web - Prepare transforms beforehand or use explicit matrices
SVG Limitations
Not all SVG features are supported. Some advanced features may not render:- Complex filters may not work
- Some CSS features are limited
- JavaScript in SVG is not supported
- External resources may not load
See Also
- Images Overview - Loading and displaying raster images
- Pictures - Recording drawing commands
- Skottie - After Effects animations