Skip to main content

Image Shaders

Image

Returns an image as a shader with the specified tiling. It will use cubic sampling.

NameTypeDescription
imageSkImageImage instance.
tx?TileModeCan be clamp, repeat, mirror, or decal.
ty?TileModeCan be clamp, repeat, mirror, or decal.
fm?FilterModeCan be linear or nearest.
mm?MipmapModeCan be none, linear or nearest.
fit?FitCalculate the transformation matrix to fit the rectangle defined by fitRect. See images.
rect?SkRectThe destination rectangle to calculate the transformation matrix via the fit property.
transform?Transforms2dsee transformations.

Example

tsx
import {
Canvas,
Circle,
ImageShader,
Skia,
Shader,
useImage
} from "@shopify/react-native-skia";
 
const ImageShaderDemo = () => {
const image = useImage(require("../../assets/oslo.jpg"));
if (image === null) {
return null;
}
return (
<Canvas style={{ flex: 1 }}>
<Circle cx={128} cy={128} r={128}>
<ImageShader
image={image}
fit="cover"
rect={{ x: 0, y: 0, width: 256, height: 256 }}
/>
</Circle>
</Canvas>
);
};
tsx
import {
Canvas,
Circle,
ImageShader,
Skia,
Shader,
useImage
} from "@shopify/react-native-skia";
 
const ImageShaderDemo = () => {
const image = useImage(require("../../assets/oslo.jpg"));
if (image === null) {
return null;
}
return (
<Canvas style={{ flex: 1 }}>
<Circle cx={128} cy={128} r={128}>
<ImageShader
image={image}
fit="cover"
rect={{ x: 0, y: 0, width: 256, height: 256 }}
/>
</Circle>
</Canvas>
);
};

Result

Image Shader