What are Pictures?
A Picture is an immutable recording of drawing operations. Once created, it can be drawn multiple times on any canvas without re-recording. This is ideal when:- The number of drawing commands varies per frame
- You need to execute loops of drawing operations
- You want to cache complex drawings for reuse
- You’re creating procedural graphics
Picture Component
ThePicture component renders a recorded picture on the canvas.
Props
| Name | Type | Description |
|---|---|---|
| picture | SkPicture | The picture to render |
Basic Example
Here’s a simple example that draws a circle:Animated Circle Trail
This example demonstrates the power of Pictures for variable drawing commands:Recording Pictures
Creating a Recorder
Begin Recording
Define the recording bounds:Draw on Canvas
Use the canvas to record drawing commands:Finish Recording
Complex Example: CMY Circles
Applying Effects
Pictures don’t follow standard painting rules. Use thelayer property to apply effects:
With Color Filters
Serialization
Pictures can be serialized for debugging or storage:Picture Instance Methods
makeShader
Convert a picture into a shader:serialize
Export as bytes:Advanced Patterns
Procedural Pattern
Reusable Picture
Performance Tips
- Cache pictures with
useMemowhen content doesn’t change - Reuse Paint instances across recordings
- Keep recorder instances outside render when possible
- Use
useDerivedValuefor animated pictures - Serialize expensive pictures for debugging
When to Use Pictures
Use Pictures when:- Drawing a variable number of shapes
- Creating procedural graphics
- Caching complex drawing operations
- Building custom components with loops
- Drawing a fixed number of shapes
- Using declarative syntax
- Leveraging React Native Skia’s animation system
- Building standard UI elements
See Also
- Canvas API - Direct canvas drawing
- SVG - Vector graphics
- Skottie - After Effects animations
- Images Overview - Raster images