2 回答
慕标5832272
TA贡献1966条经验 获得超4个赞
比如用 const coordinate = [[x1,y1],[x2,y2]] 表示人脸坐标
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
const coordinate = [[100,100],[200,200]]
const [x1, y1] = coordinate[0];
const [x2, y2] = coordinate[1];
const clipWidth = Math.abs(x2 - x1);
const clipHeight = Math.abs(y2 - y1);
const img = new Image()
img.src = "原图URL"
img.onload = ()=>{
ctx.drawImage(img,x1,y1,clipWidth,clipHeight,0,0,clipWidth,clipHeight)
const data = canvas.toDataURL('image/png')
}
添加回答
举报
0/150
提交
取消