Hi everyone. Is it possible to save canvas data to image .jpg file using $cordovaFile plugin? Thanks
You can use the https://github.com/devgeeks/Canvas2ImagePlugin plugin for this (note that this saves the image to the camera roll…).
var canvas = document.createElement( 'canvas' );
var ctx = canvas.getContext( '2d' );
void ctx.drawImage( this, 0, 0, img.width, img.height);
var dataURI = canvas.toDataURL().replace( /data:image\/png;base64,/, '' );
function successCallback( result ) {
q.resolve( 'file:///' + result );
}
function failureCallback( err ) {
console.error( err );
q.reject( err );
}
cordova.exec( successCallback, failureCallback, "Canvas2ImagePlugin", "saveImageDataToLibrary", [dataURI] );
2 Likes