我在react-konva中有一个Image组件,想要添加border-radius: 8px。哪种方法最简单?
发布于 2019-12-25 05:35:56
有了this amazing comment作为参考,这个问题可以很容易地解决:
...
<Group
clipFunc={ctx => calcClipFunc(ctx, x, y, width, height, radius)}
>
<Image
image={image}
width={width}
height={height}
x={x}
y={y}
/>
</Group>以及上一条注释中的calcClipFunc()函数:
function calcClipFunc(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}发布于 2019-12-25 06:02:02
在Stage中剪辑图像:
// image.width, image.height
<Stage width={200} height={200} style={{borderRadius: '8px', overflow: 'hidden'}}>
<Layer >
<Image image={this.state.image} />
</Layer>
</Stage>https://stackoverflow.com/questions/59473505
复制相似问题