ImageShader component allows you to use images as shaders, providing control over tiling, fitting, and transformations. This enables you to create patterns, textures, and complex visual effects.
Image Shader
TheImageShader returns an image as a shader with configurable tiling modes. It uses cubic sampling for high-quality rendering.
Props
| Name | Type | Description |
|---|---|---|
| image | SkImage | The image instance to use as a shader |
| tx | TileMode | Horizontal tiling mode: clamp, repeat, mirror, or decal (default: decal) |
| ty | TileMode | Vertical tiling mode: clamp, repeat, mirror, or decal (default: decal) |
| fit | Fit | How to fit the image in the destination rectangle (default: none) |
| rect | SkRect | Destination rectangle for fit calculation |
| transform | Transform2d | Additional transformations to apply (see transformations) |
| sampling | Sampling | Sampling method for the image (see sampling options) |
Basic Example
Tiling Modes
Control how the image repeats using tile modes:Clamp
Extends edge pixels:Repeat
Repeats the image:Mirror
Mirrors the image:Decal
Draws the image once, transparent elsewhere:Fitting Images
Thefit property works with the rect property to control how the image fits within a rectangle:
Contain
Fits the entire image within the bounds:Cover
Covers the entire rectangle, may crop the image:Fill
Stretches the image to fill the rectangle:Other Fit Options
fitWidth: Scales to match widthfitHeight: Scales to match heightscaleDown: Like contain, but never scales upnone: No fitting applied (default)
Transformations
Apply transformations to image shaders:Sampling Options
Control image quality with sampling options:Cubic Sampling (Best Quality)
Filter Modes
Creating Patterns
Tiled Pattern
Kaleidoscope Effect
Combining with Other Shaders
Blend image shaders with other effects:Using with Runtime Shaders
Image shaders can be passed to custom runtime shaders:Performance Tips
- Reuse
SkImageinstances when possible - Use appropriate sampling modes for your use case
- Consider using lower resolution images for patterns
- Cache images loaded with
useImage - Use
decaltile mode when you don’t need tiling
Loading Images
Images are loaded using theuseImage hook:
See Also
- Images Overview - Loading and displaying images
- Gradients - Gradient shaders
- Shading Language - Custom runtime shaders
- Sampling Options - Image sampling details