getList() {
let pilotRect = {
left: 190,
right: 290,
top: 160,
bottom: 260
};
this.initPicture('/static/images/car.png', pilotRect);
},
initPicture(imgUrl, rect) {
let img = new Image();
img.src = imgUrl;
img.setAttribute('crossOrigin', 'Anonymous');
let imgW = Math.abs(rect.right - rect.left);
let imgH = Math.abs(rect.bottom - rect.top);
let canvas = document.createElement('canvas');
let context = canvas.getContext('2d');
canvas.width = imgW;
canvas.height = imgH;
context.fillStyle = '#FFF';
context.fillRect(0, 0, imgW, imgH);
img.onload = () => {
context.drawImage(img, -rect.left, -rect.top);
this.imgTest = canvas.toDataURL('image/jpeg');
};
},
例如裁剪出抓拍车辆图片中的主驾驶和副驾驶人员图片等