I am trying to call the function save after I make sure the image is completely loaded, but it does not work!
In <script>
:
//change image width and heignt (100*100).
var canvas = document.createElement('canvas');
var width = 100; var height = 100;
canvas.width = 100; canvas.height = 100;
var imgTile = new Image(); imgTile.src = this.cropImg;
imgTile.onload = function(){
canvas.getContext('2d').drawImage(imgTile, 0, 0, width, height);
var img_data = canvas.toDataURL('image/jpeg');
console.log("img_data: " + img_data);
this.New_cropImg = img_data;
this.showImage = true;
this.save(this.New_cropImg);
};
and function save is already defined and works perfectly outside the onload function.
How can I solve this problem?