我发现我必须使用
img-use
将图像加载到konva中的图层。它适用于jpg和png,但不适用于svg。我还可以做些什么来让一层有SVG?
import useImage from "use-image";
const [backgroundImage] = useImage(
`https://ticket-t01.s3.eu-central-1.amazonaws.com/madach-2.svg` || ""
);
实际上,它加载的图像位非常像素化。从Illustrator重新导出时,我是否要保存SVG?
<Stage
width={
gridWidth ? (gridWidth >= 600 ? gridWidth : gridWidth) : 200
}
height={
layout && gridWidth
? Math.round(gridWidth / layout.aspectRatio)
: 200
}
>
<Layer>
<Rect
x={0}
y={0}
width={gridWidth || 200}
height={
layout && gridWidth
? Math.round(gridWidth / layout.aspectRatio)
: 200
}
fillPatternImage={backgroundImage}
fillPatternRepeat="no-repeat"
fillPatternScale={{
x: (gridWidth || 200) / (backgroundImage?.width || 200),
y:
(layout && gridWidth
? Math.round(gridWidth / layout.aspectRatio)
: 200) / (backgroundImage?.height || 200),
}}
/>
</Layer>