-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFilterDemo.js
180 lines (161 loc) · 5.97 KB
/
FilterDemo.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import React, { Component ,PropTypes} from 'react';
import {InteractionManager,ScrollView,Text,View,TouchableOpacity, Navigator,StyleSheet,Platform,Dimensions, Image,TextInput} from 'react-native';
let {width,height,scale}=Dimensions.get('window');
import {F1977,Amaro,Brannan,Earlybird,Hefe,Hudson,Inkwell,Lokofi,LordKelvin,Nashville,Normal,Rise,Sierra,Sutro,Toaster,Valencia,Walden,XproII} from "gl-react-instagramfilters";
import {Surface ,resolveAssetSource} from "gl-react-native";
const {Image: GLImage} = require("gl-react-image");
import Camera from 'react-native-camera';
export default class FilterDemo extends Component {
constructor(props) {
super();
this.state = {
data:{},
type:1,
filterImg:require('./replace.png'),
cameraView:<Camera
captureTarget={Camera.constants.CaptureTarget.temp}
ref={(cam) => {
this.camera = cam;
}}
style={styles.preview}
aspect={Camera.constants.Aspect.fill}
captureMode = {Camera.constants.CaptureMode.fit}
orientation={Camera.constants.Orientation.portrait}
captureAudio = {false}
>
</Camera>,
isCamera:true
};
}
render() {
return (
<View style={styles.container}>
<View>
{this.state.cameraView}
</View>
<ScrollView horizontal ={true} style={{height:100,marginTop:20}}>
<TouchableOpacity onPress={this.selectFilter}>
<Surface height={100} width={100}>
<GLImage
source={resolveAssetSource(this.state.filterImg)}
imageSize={{ width: 100, height: 100 }}
resizeMode="stretch"
/>
</Surface>
</TouchableOpacity>
<Surface height={100} width={100}>
<F1977>
<GLImage
source={resolveAssetSource(this.state.filterImg)}
imageSize={{ width: 100, height: 100 }}
resizeMode="stretch"
/>
</F1977>
</Surface>
<Surface height={100} width={100}>
<Sierra>
<GLImage
source={resolveAssetSource(this.state.filterImg)}
imageSize={{ width: 100, height: 100 }}
resizeMode="stretch"
/>
</Sierra>
</Surface>
<Surface height={100} width={100}>
<Inkwell>
<GLImage
source={resolveAssetSource(this.state.filterImg)}
imageSize={{ width: 100, height: 100 }}
resizeMode="stretch"
/>
</Inkwell>
</Surface>
</ScrollView>
<View style={{flexDirection:'row',justifyContent:'space-around'}}>
<Text style={styles.capture} onPress={this.takePicture}>拍摄</Text>
<Text style={styles.capture} onPress={this.cancelPicture}>取消</Text>
</View>
</View>
)
}
// 拍照执行
takePicture = ()=> {
if (!this.state.isCamera){return}
this.camera.capture()
.then((data) => {
this.setState({
data:data,
});
let img = {uri:this.state.data.path};
this.setState({
filterImg:img,
cameraView:<Surface height={height - 400} width={width}>
<GLImage
source={resolveAssetSource(img)}
imageSize={{ width: width, height: height - 400 }}
resizeMode="stretch"
/>
</Surface>,
isCamera:false
});
})
.catch(err => console.error(err));
};
// 取消执行
cancelPicture = ()=> {
this.setState({
cameraView:<Camera
captureTarget={Camera.constants.CaptureTarget.temp}
ref={(cam) => {
this.camera = cam;
}}
style={styles.preview}
aspect={Camera.constants.Aspect.fill}
captureMode = {Camera.constants.CaptureMode.fit}
orientation={Camera.constants.Orientation.portrait}
captureAudio = {false}
>
</Camera>,
isCamera:true
});
};
// 选中滤镜执行
selectFilter = ()=>{
let img = {uri:this.state.data.path};
this.setState({
cameraView:<Surface height={height - 400} width={width}>
<XproII>
<GLImage
source={resolveAssetSource(img)}
imageSize={{ width, height: height - 400 }}
resizeMode="stretch"
/></XproII>
</Surface>
})
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
height: height - 400,
width: width
},
capture: {
flex: 0,
backgroundColor: '#fff',
borderRadius: 5,
color: '#000',
padding: 10,
margin: 40,
fontSize:30
},
filterList:{
width: 100,
height: 100
}
});