简体   繁体   中英

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

I am struggling with hexagon shape on react native can anyone have some idea about how does it work using svg in react native or any alternate way?

  • creating shapes using js
  • image cutout of hexagon
  • masking image[enter image description here][1]

I'm trying this below image. https://i.stack.imgur.com/MLDFl.jpg

This is My code:

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>


    );
}

This kind of image can be created with my react-native-image-filter-kit module:

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' }}
      />
    }
  />
) 

结果

Note that shape generation is not supported currently, so you need to use another image for masking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM