-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReactNativeTakeSnapShot.js
94 lines (84 loc) · 1.99 KB
/
ReactNativeTakeSnapShot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// 截屏生成图片
import React, {Component} from 'react';
import {
View,
StyleSheet,
Image,
Text,
ART
} from 'react-native';
var {
Shape,
Group,
Transform,
Surface,
Rectangle
} = ART;
import { captureRef, captureScreen } from "react-native-view-shot";
export default class App extends Component {
// 构造
constructor(props) {
super(props);
// 初始状态
this.state = {
uri: ''
};
}
takeToImage() {
// captureScreen({
// format: "jpg",
// quality: 0.8
// })
// .then(
// uri => this.setState({
// uri:uri
// }),
// error => console.error("Oops, snapshot failed", error)
// );
captureRef(this.refs.location, {
format: "jpg",
quality: 1
})
.then(
uri => this.setState({
uri:uri
}),
error => console.error("Oops, snapshot failed", error)
);
}
render() {
const path = ART.Path();
path.moveTo(1,1); //将起始点移动到(1,1) 默认(0,0)
path.lineTo(300,1); //连线到目标点(300,1)
return (
<View style={styles.container}>
<View ref='location' style={styles.artContainer}>
<Surface
width={300}
height={300}>
<Group>
<Shape d={"M160 160 A 45 45, 0, 0, 1, 115 205"} stroke="#000000" strokeWidth={3} />
<Shape d={"M160 160 A 45 45, 0, 0, 1, 115 205"} stroke="#000000" strokeWidth={3} />
</Group>
</Surface>
</View>
<Text onPress={()=>this.takeToImage()}>生成图片</Text>
<Image source={{uri: this.state.uri}} style={{borderWidth:1, borderColor:'black',height:300,width:300}}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white'
},
artContainer: {
height: 300,
width: 300,
backgroundColor: 'red',
justifyContent: 'center'
}
});