canvas中坐标处理

代码

function windowTocanvas(canvas, x, y) {
    var bbox = canvas.getBoundingClientRect();
    return {
        x: x - bbox.left * (canvas.width / bbox.width),
        y: y - bbox.top * (canvas.height / bbox.height)
    };

}

// 其中x为clientX y为clientY

你可能感兴趣的:(canvas中坐标处理)