出现下面这种情况的同学,图片的地址必须是从网上的图片才可以,例如http://example.com/image,本地图片就会抛出这种错误。
Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
2016-07-08
我觉得用offsetX 和offsetY 会好些吧 canvas.getBoundingClientRect() 里面,left 和.top 是指当前页面显示部分离文档最上端或左端的距离
2016-06-21
@Caihong_deng 加入一句判断,if(scale<1){
context.drawImage(watercanvas,imgWidth-watercanvas.width+dx,imgHeight-watercanvas.height+dy);//缩放比例小于1时,图片小于canvas画布,用图片的宽高减去水印的宽高就可以固定在水印右下角
}else{
context.drawImage(watercanvas,canvas.width-watercanvas.width,canvas.height-watercanvas.height);
}
context.drawImage(watercanvas,imgWidth-watercanvas.width+dx,imgHeight-watercanvas.height+dy);//缩放比例小于1时,图片小于canvas画布,用图片的宽高减去水印的宽高就可以固定在水印右下角
}else{
context.drawImage(watercanvas,canvas.width-watercanvas.width,canvas.height-watercanvas.height);
}
2016-06-16