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