Paint component controls how shapes and other drawing elements are rendered. It defines styling properties like color, opacity, blend modes, and effects.
Basic Usage
Props
Color and Opacity
Sets the color for drawing operations. Accepts:
- Named colors:
"red","blue", etc. - Hex colors:
"#FF0000","#F00" - RGB/RGBA:
"rgb(255, 0, 0)","rgba(255, 0, 0, 0.5)" - HSL/HSLA:
"hsl(0, 100%, 50%)"
Alpha value from 0 (fully transparent) to 1 (fully opaque)
Style
Whether to fill or stroke shapes:
fill: Fills the interior of shapesstroke: Draws only the outline
Stroke Properties
Width of strokes in pixels
How line ends are drawn:
butt: Flat end at the endpointround: Rounded end extending past the endpointsquare: Square end extending past the endpoint
How corners are drawn:
miter: Sharp cornerround: Rounded cornerbevel: Beveled corner
Limit for miter joins before beveling
Blend Mode
How colors are composited. Common values:
srcOver: Default alpha blendingmultiply: Multiplies colorsscreen: Inverted multiplyoverlay: Combination of multiply and screendarken,lighten,colorDodge,colorBurn, etc.
Effects and Filters
Enable anti-aliasing for smoother edges
Enable dithering to reduce color banding
Applying Effects
ThePaint component can contain child components that add effects:
Shaders
Image Filters
Color Filters
Examples
Stroked Shape
Semi-Transparent Fill
Blend Mode Effect
Multiple Effects
Gradient with Stroke
Imperative API
You can also create paint objects imperatively:Paint Methods
Sets the paint color
Sets alpha value (0-1)
Sets fill or stroke style
Sets stroke width
Sets stroke cap style
Sets stroke join style
Sets miter limit
Sets blend mode
Enables/disables anti-aliasing
Enables/disables dithering
Sets a shader for gradients or patterns
Sets an image filter (blur, etc.)
Sets a color filter
Sets a mask filter
Sets a path effect (dash, etc.)
Creates a copy of the paint
Resets paint to default values
Performance Tips
- Reuse paint objects when possible
- Avoid creating new paint instances in render methods
- Use
useMemofor paint configurations that don’t change - Simple fills are faster than strokes
- Anti-aliasing has a small performance cost