【发布时间】:2017-05-20 21:21:40
【问题描述】:
我尝试根据需要将图片放置在分配的坐标上, 但是我不能画出的形状和角度都没有匹配和纠正,只有左上角匹配
var _width, _height;
var img = new Image();
var img2 = new Image(),
img2Widht = 0,
img2Height = 0;
img.src = "http://production.manboker.com/share/1.jpg";
var canvas = document.getElementById("canvas");
img.onload = function() {
canvas.width = _width = this.width;
canvas.height = _height = this.height;
img2.src = "http://production.manboker.com/share/2.png";
img2.onload = function() {
img2Widht = coor['rightTop'][0] - coor['leftTop'][0];
img2Height = coor['leftBottom'][1] - coor['leftTop'][1];
step1();
}
}
var coor = {
leftTop: ["92", "569"],
rightTop: ["672", "569"],
leftBottom: ["109", "1437"],
rightBottom: ["723", "1437"]
}
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
function step1() {
ctx.clearRect(0, 0, _width, _height);
ctx.globalCompositeOperation = 'source-over';
ctx.drawImage(img,0,0);
//ctx.globalCompositeOperation = "multiply";
step2();
}
function step2() {
ctx.drawImage(img2, 92,569,img2Widht,img2Height);
}
* {
padding: 0;
margin: 0;
}
html,
body {
position: relative;
overflow: hidden;
height: 100%;
width:100%;
}
<canvas id="canvas" style="position:absolute;"></canvas>
谁能告诉我怎么画出正确的角度?
【问题讨论】:
-
所以你想让图像的角在声明的位置?它们是形成一个矩形还是只是随机点?
-
从外观上看,图像应该有点歪斜。这可能是可能的,但它会使用一些矩阵数学
标签: javascript html image html5-canvas