reactjs - 如何将边框半径添加到 react-konva Image 对象?
问题描述
我有一个Image
组件react-konva
并想添加border-radius: 8px
. 哪种方法最简单?
解决方案
有这个惊人的评论作为参考,这个问题可以很容易地解决:
...
<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();
}
推荐阅读
- html - 如何使这个 CSS 树居中?
- c++ - 在内联函数的定义中使用 constexpr 变量时可能的 ODR 违规(在 C++14 中)
- list - 内存泄漏与 swiftUI 列表和 Firebase 数据库观察 childAdded
- python - 确定两条线位置的有效方法
- microk8s - 如何从 MiroK8S 重命名 docker 镜像?
- powershell - 如何使用日期参数通过 CSV 中的 PowerShell 自动启用/禁用 AD 中的用户
- angular - Angular 从组件内部更改 styleUrls 值
- asp.net-core - 在 TagHelper 中查找子元素
- r - 如何获得不同时符合两个标准的唯一 ID 的数量(例如,在不同的行中)?
- excel - 如果值为 0,则隐藏工作表,否则使其可见