I have integrated the plugin from https://github.com/blinkmobile/cordova-plugin-sketch into my Ionic 3 project.
One remaining crucial task is to extract the result from the callback functions so that I can continue working with it.
Below is a snippet of my code:
anhangArray: Array<{ name: string, value: string }>=[];
takePhoto() {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true,
allowEdit: false,
}
this.camera.getPicture(options).then((imageData) => {
// imageData can be base64 encoded or a file URI
// If it's base64:
//base64Image = 'data:image/jpeg;base64,' + imageData;
//>>> FILE_URI
this.getSketch(imageData);
}, (err) => {
// Handle error
});
}
getSketch(src: string) {
window.navigator.sketch.getSketch(this.onSuccess, this.onFail, {
destinationType: window.navigator.sketch.DestinationType.DATA_URL,
encodingType: window.navigator.sketch.EncodingType.JPEG,
inputType: window.navigator.sketch.InputType.FILE_URI,
inputData: src
});
}
onSuccess(imageData) {
var _mythis = this;
if (imageData == null) { return; }
// Perform further actions here!
setTimeout(function () {
if (imageData.indexOf("data:image") >= 0) {
} else {
imageData = "data:image/jpeg;base64," + imageData;
}
_mythis.anhangArray.push({ name: "anhang_" + parseInt(_mythis.user._kunnr), value: imageData });
console.log(this.anhang);
}, 0);
}
Error: Uncaught TypeError: Cannot read property 'anhangArray' of undefined