在画布中重绘图像

时间:2015-05-13 06:38:47

标签: javascript html html5 canvas draw

我正在将图像绘制到画布中。单击按钮时,将执行以下代码:

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源正在改变。该代码仅适用于第一次,但第二次单击该按钮时,它不会更新画布。如何在画布中重绘图像?

0 个答案:

没有答案