我想将图像绘制到画布上,然后允许用户通过 sketch.js 在其上绘制一些草图。现在的情况是:
1.the image has been drawn on the canvas successfully
2. but when my mouse over the canvas, then image disappeared, and the canvas shows empty
3. when I dragged the mouse, some sketch shows on the empty canvas(the sketch looks correct)
所以,我把这两个功能都做好了,但我对两者之间的部分感到困惑。我希望在画布上画出带有图像的草图。这是我的代码:
索引.html:
<canvas id="mysketch" width="578" height="400" style="margin: 0px; "></canvas>
画布.js:
var mysketch = jQuery("#mysketch");
// draw the captured image to canvas
var displayImage = function() {
var context = mysketch.get(0).getContext("2d");
var image = new Image();
image.onload = function() {
context.drawImage(image, 0, 0);
}
// prepend the required image info again
image.src = dataURL;
// call sketch.js to draw sketch on the canvas
mysketch.sketch({defaultColor: "#ff0"});
}