React Native 生成图片
发布时间:2020-12-15 06:48:28 所属栏目:百科 来源:网络整理
导读:方法简介: takeSnapshot方法是react-native自带的生成图片的属性,可以将”screen”,“window” 或者 “view”生成对应的图片。 兼容: takeSnapshot之前的写法是在UIManager中,新版本后放到了ReactNative模块中。 使用: 直接使用以下方法即可调用生成对
方法简介: takeSnapshot方法是react-native自带的生成图片的属性,可以将”screen”,“window” 或者 “view”生成对应的图片。 兼容: 使用: 注意:需要引用ReactNative模块 ReactNative.takeSnapshot('screen',{format: 'png',quality: 1}).then(
(uri) => this.setState({uri:uri})
).catch(
(error) => alert(error)
);
完整代码: import React,{ Component } from 'react';
var ReactNative = require('react-native');
import { AppRegistry,Text,View,Dimensions,Image } from 'react-native';
var {height,width} = Dimensions.get('window');
export default class pictureDemo extends Component {
constructor(props){
super(props);
this.state = {uri: 'null'}
}
takeToImage() {
ReactNative.takeSnapshot(this.refs.location,quality: 1}).then(
(uri) => this.setState({uri:uri})
).catch(
(error) => alert(error)
);
}
render(){
console.log(this.state.uri);
return (
<View>
<View ref='location' style={{backgroundColor: 'green',padding: 12,margin: 20}}>
<Text>this is a girl</Text>
<Text>this is a friend</Text>
<Text>o</Text>
<Text>this is a girl friend</Text>
</View>
<Text onPress={()=>this.takeToImage()}>生成图片</Text>
<Image style={{borderWidth: 1,height: 100,width: width,marginTop: 10}} source={{uri: this.state.uri}} />
</View>
);
}
}
效果图: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- xstream解析xml中有很多重复的field的xml
- 你的编程生涯可以从Swift开始!——专访Paris Buttfield-Ad
- c – 如何提取一组可选参数的参数,并使用它们来调用另一个函
- ruby – 如何在Dreamhost Rails 3.0.4上部署测试应用程序?
- c – Qt – 如何在QVBoxLayout中放置具有左右边距的QTextEd
- dojo041中dojo.byId存在问题
- Cocos2d-x的学习之旅(三)自己的 HelloWorld
- xml – 我应该使用XSD 1.1来构建开放标准吗?
- iphone – CollectionView Ios 6问题
- ruby-on-rails – Capistrano从旧版本发出错误. ::的Action