Created
October 19, 2018 11:16
-
-
Save nazrdogan/249da2ff62a928c9803a0eb9f0c8c7cd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
saveCanvasImage() { | |
var dataUrl = this.canvasElement.toDataURL(); | |
var imageData = this.canvasElement.toDataURL('image/jpeg').replace(/^data:image\/(png|jpg|jpeg);base64,/, ""); //remove mimetype | |
window["DatecsPrinter"].printImage( | |
imageData, //base64 | |
canvas.width, | |
canvas.height, | |
1, | |
function() { | |
console.log("Printed"); | |
}, | |
function(error) { | |
alert(JSON.stringify(error)); | |
} | |
) | |
}; | |
let ctx = this.canvasElement.getContext('2d'); | |
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); // Clears the canvas | |
let name = new Date().getTime() + '.png'; | |
let path = this.file.dataDirectory; | |
let options: IWriteOptions = { replace: true }; | |
var data = dataUrl.split(',')[1]; | |
let blob = this.b64toBlob(data, 'image/png'); | |
this.file.writeFile(path, name, blob, options).then(res => { | |
this.storeImage(name); | |
}, err => { | |
console.log('error: ', err); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment