首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为react-konva图像对象添加边框半径?

如何为react-konva图像对象添加边框半径?
EN

Stack Overflow用户
提问于 2019-12-25 05:23:33
回答 2查看 353关注 0票数 1

我在react-konva中有一个Image组件,想要添加border-radius: 8px。哪种方法最简单?

EN

回答 2

Stack Overflow用户

发布于 2019-12-25 05:35:56

有了this amazing comment作为参考,这个问题可以很容易地解决:

代码语言:javascript
复制
  ...

  <Group
    clipFunc={ctx => calcClipFunc(ctx, x, y, width, height, radius)}
  >
    <Image
      image={image}
      width={width}
      height={height}
      x={x}
      y={y}
    />
  </Group>

以及上一条注释中的calcClipFunc()函数:

代码语言:javascript
复制
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();
}
票数 2
EN

Stack Overflow用户

发布于 2019-12-25 06:02:02

在Stage中剪辑图像:

代码语言:javascript
复制
  // image.width, image.height
  <Stage width={200} height={200} style={{borderRadius: '8px', overflow: 'hidden'}}>
    <Layer >
      <Image image={this.state.image} />
    </Layer>
  </Stage>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59473505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档