-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22ca537
commit 114e16c
Showing
2 changed files
with
61 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,77 @@ | ||
import {Platform, Page, NavController, ActionSheet} from 'ionic-angular'; | ||
import {Page, Loading, NavController, ActionSheet} from 'ionic-angular'; | ||
import {Camera} from 'ionic-native'; | ||
|
||
@Page({ | ||
templateUrl: 'build/pages/home/home.html' | ||
}) | ||
export class HomePage { | ||
constructor(private platform: Platform, private nav: NavController) { } | ||
|
||
srcImage: string; | ||
|
||
constructor(private nav: NavController) { } | ||
|
||
presentActionSheet() { | ||
let actionSheet = ActionSheet.create({ | ||
buttons: [ | ||
{ | ||
text: 'Choose Photo', | ||
handler: () => { | ||
console.log('Choose Photo'); | ||
this.getPicture(0); // 1 == Library | ||
} | ||
}, | ||
{ | ||
text: 'Take Photo', | ||
handler: () => { | ||
console.log('Take Photo'); | ||
this.getPicture(1); // 1 == Camera | ||
} | ||
}, | ||
{ | ||
text: 'Cancel', | ||
role: 'cancel', | ||
text: 'Demo Photo', | ||
handler: () => { | ||
console.log('Cancel clicked'); | ||
this.srcImage = 'demo.png'; | ||
} | ||
}, | ||
{ | ||
text: 'Cancel', | ||
role: 'cancel' | ||
} | ||
] | ||
}); | ||
this.nav.present(actionSheet); | ||
} | ||
|
||
getPicture (sourceType: number) { | ||
// You can check the values here: | ||
// https://github.com/driftyco/ionic-native/blob/master/src/plugins/camera.ts | ||
Camera.getPicture({ | ||
quality: 100, | ||
destinationType: 0, // DATA_URL | ||
sourceType: sourceType, | ||
allowEdit: true, | ||
saveToPhotoAlbum: false, | ||
correctOrientation: true | ||
}).then(imageData => { | ||
this.srcImage = `data:image/jpeg;base64,${imageData}`; | ||
}, error => { | ||
console.log(`ERROR -> ${JSON.stringify(error)}`); | ||
}); | ||
} | ||
|
||
analyze () { | ||
let loading = Loading.create({ | ||
content: 'Reading...' | ||
}); | ||
this.nav.present(loading); | ||
OCRAD(document.getElementById('image'), text => { | ||
loading.dismiss(); | ||
console.log(text); | ||
alert(text); | ||
}); | ||
} | ||
|
||
restart () { | ||
this.srcImage = ''; | ||
this.presentActionSheet(); | ||
} | ||
|
||
} |