React Native学习-将 'screen', 'window' or a view生成图片


https://github.com/facebook/react-native/commit/ac12f986899d8520527684438f76299675dc0daa

这是react-native自带的生成图片的属性,所以使用之前只需要引用UIManager属性即可;

View生成图片:

state = {
    uri: null
};

takeToImage() {
    UIManager.takeSnapshot(this.refs.location, {format: 'png', quality: 0.8}).then(
        (uri) => this.setState({uri})
    ).catch(
        (error) => alert(error)
    );
}

render() {
    return (<View>
            <View ref='location'>
                <Text>东经</Text>
                <Text>东经</Text>
                <Text>西经</Text>
                <Text>东经</Text>
            </View>

            <Text onPress={()=>this.takeToImage()}>生成图片</Text>

            <Image source={{uri: this.state.uri}} style={{borderWidth:1,height:50,width:300}}/>
        </View>
    )
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM