Hi
I have a mouse pen / tablet pen.
(
It's a tablet with a pen.Not actually a tablet.Something like a board with pen).
I want to write an app, so that someone can write something on it and save it as an image. I wrote the app.
Below is the problem i faced :-
- The tablet covers whole screen. But, I don't want the whole screen.
- I have a canvas to write on and i just want that tablet fit into that canvas.
There should be way. Please help me. Sorry for my english by the way.
Here is my code:
What I have tried:
<!DOCTYPE html>
<html lang="en">
<canvas id="can" width="100" height="100" style="position:absolute;top:10%;left:10%;border:2px solid;">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
var canvas = document.querySelector( 'canvas' ),
c = canvas.getContext( '2d' ),
mouseX = 0,
mouseY = 0,
width = 300,
height = 300,
colour = 'red',
mousedown = false;
canvas.width = width;
canvas.height = height;
function draw() {
if (mousedown) {
c.fillStyle = colour;
c.beginPath();
c.arc( mouseX, mouseY, 2 , 0, Math.PI*2, true );
c.closePath();
c.fill();
}
}
canvas.addEventListener( 'mousemove', function( event ) {
if( event.offsetX ){
mouseX = event.offsetX;
mouseY = event.offsetY;
} else {
mouseX = event.pageX - event.target.offsetLeft;
mouseY = event.pageY - event.target.offsetTop;
}
draw();
}, false );
canvas.addEventListener( 'mousedown', function( event ) {
mousedown = true;
}, false );
canvas.addEventListener( 'mouseup', function( event ) {
mousedown = false;
}, false );
var link = document.createElement('a');
link.innerHTML = 'download image';
link.addEventListener('click', function(ev) {
link.href = canvas.toDataURL();
link.download = "mypainting.png";
}, false);
document.body.appendChild(link);
</script>
</body>
</html>