-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
100 lines (88 loc) · 2.58 KB
/
App.js
File metadata and controls
100 lines (88 loc) · 2.58 KB
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
/**
* ./index.js
* @author Jonathan Palma <tanpalma04@gmail.com>
*/
'use strict';
import React, { Component } from 'react';
import { Image, Platform, PixelRatio, StyleSheet, Text, TouchableNativeFeedback, TouchableOpacity, View } from 'react-native';
import ImagePicker from 'react-native-image-picker';
import RNTesseractOcr from 'react-native-tesseract-ocr';
var Button = (Platform.OS === 'android') ? TouchableNativeFeedback : TouchableOpacity;
export default class App extends React.Component {
constructor(props, context){
super(props, context);
this.state = { imgSource: null, ocrResult: null };
}
selectPhoto(){
const options = {
quality: 1.0,
maxWidth: 500,
maxHeight: 500,
storageOptions: {
skipBackup: true
}
};
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled photo picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
}
else {
var source;
if (Platform.OS === 'android') {
source = {uri: response.uri, isStatic: true};
} else {
source = {uri: response.uri.replace('file://', ''), isStatic: true};
}
this.setState({ imgSource: source });
RNTesseractOcr.startOcr(response.path, "LANG_ENGLISH")
.then((result) => {
this.setState({ ocrResult: result });
console.log("OCR Result: ", result);
})
.catch((err) => {
console.log("OCR Error: ", err);
})
.done();
}
});
}
render() {
return(
<View style={styles.container}>
<Button onPress={this.selectPhoto.bind(this)} >
<View style={[styles.img, styles.imgContainer, {marginBottom: 20}]}>
{ this.state.imgSource === null ? <Text>Select a Photo</Text> :
<Image style={styles.img} source={this.state.imgSource} />
}
</View>
</Button>
<Text>OCR Result: {this.state.ocrResult}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
imgContainer: {
borderColor: '#9B9B9B',
borderWidth: 1 / PixelRatio.get(),
justifyContent: 'center',
alignItems: 'center'
},
img: {
borderRadius: 75,
width: 150,
height: 150
}
});