码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-07-05 19:02:42      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

标签:

原文地址:http://www.cnblogs.com/maoyazhi/p/5644617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!