gpt4 book ai didi

javascript - 如何在 react 原生的 SVG 六边形形状中屏蔽用户图像

转载 作者:行者123 更新时间:2023-11-30 14:34:40 27 4
gpt4 key购买 nike

我正在为 React Native 上的六边形形状而苦苦挣扎,谁能知道在 React Native 中使用 svg 或任何替代方式是如何工作的?

  • 使用 js 创建形状
  • 六边形的图像剪切
  • 掩蔽图像[在此处输入图像描述][1]

我正在尝试下面的图片。 /image/MLDFl.jpg

这是我的代码:

渲染(){ 返回 (

        <Svg
height="300"
width="300"
viewBox="0 0 860 860"
>
<Defs>
<ClipPath id="clip">
<Polygon
strokeWidth="2"
stroke="#979797"
strokeDasharray='8,8'
strokeLinecap='butt'
fill="rgba(0, 0, 0, 0.5)"
points="258.5,223.999 130.5,298 2.5,224 2.5,76 130.5,2 258.5,76 " />
</ClipPath>
</Defs>

<Image
x="0%"
y="0%"
width="100%"
height="100%"
preserveAspectRatio="xMidYMid slice"
opacity="0.5"
href={require('./assets/Image.jpg')}
clipPath="url(#clip)"
/>

</Svg>


);
}

最佳答案

这种图像可以用我的 react-native-image-filter-kit 创建模块:

import { Image } from 'react-native'
import { DstATopComposition } from 'react-native-image-filter-kit'

const style = { width: 320, height: 320 }

const masked = (
<DstATopComposition
dstImage={
<Image
style={style}
source={{ uri: '/image/MLDFl.jpg' }}
/>
}
srcImage={
<Image
style={style}
source={{ uri: 'http://www.myiconfinder.com/uploads/iconsets/256-256-53d5151ca4f467ed9951f85024881c85.png' }}
/>
}
/>
)

result

请注意,目前不支持形状生成,因此您需要使用其他图像进行 mask 。

关于javascript - 如何在 react 原生的 SVG 六边形形状中屏蔽用户图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50597073/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com