我正在将图像绘制到画布中。单击按钮时,将执行以下代码:
function somefunction(newImage){
var myid_signature = document.getElementById("cnv");
var myid_ctx_signature= myid_signature.getContext('2d');
var myid_signature_image = new Image();
myid_signature_image.src = newImage
if (myid_signature_image.complete){
myid_ctx_signature.drawImage(myid_signature_image,0,0, myid_signature_image.width, myid_signature_image.height, 0, 0, myid_signature.width, myid_signature.height);
}else{
myid_signature_image.onload = function () {
myid_ctx_signature.drawImage( myid_signature_image,0,0, myid_signature_image.width, myid_signature_image.height, 0, 0, myid_signature.width, myid_signature.height);
};
}
}
myid_signature_image源正在改变。该代码仅适用于第一次,但第二次单击该按钮时,它不会更新画布。如何在画布中重绘图像?