簡體   English   中英

如何在本機上以SVG六角形形狀遮蓋用戶圖像

[英]How to mask user image in SVG hexagon shape on react native

我在React Native上遇到六角形的問題,有人能對使用SVG以react native或任何其他方式如何工作有任何想法嗎?

  • 使用js創建形狀
  • 六角形圖像切口
  • 遮罩圖像[在此處輸入圖像描述] [1]

我正在嘗試下面的圖像。 https://i.stack.imgur.com/MLDFl.jpg

這是我的代碼:

render(){return(

        <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: 'https://i.stack.imgur.com/MLDFl.jpg' }}
      />
    }
    srcImage={
      <Image
        style={style}
        source={{ uri: 'http://www.myiconfinder.com/uploads/iconsets/256-256-53d5151ca4f467ed9951f85024881c85.png' }}
      />
    }
  />
) 

結果

請注意,當前不支持形狀生成,因此您需要使用其他圖像進行遮罩。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM