Skip to content

Instantly share code, notes, and snippets.

@nazrdogan
Created October 19, 2018 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nazrdogan/249da2ff62a928c9803a0eb9f0c8c7cd to your computer and use it in GitHub Desktop.
Save nazrdogan/249da2ff62a928c9803a0eb9f0c8c7cd to your computer and use it in GitHub Desktop.
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