【发布时间】:2023-01-21 09:19:10
【问题描述】:
我正在尝试在画布上绘制图像以在功能上与打字稿做出反应。
我尝试将图像绘制到画布上,但是画布上什么也没有发生,我的控制台日志返回 undefined 不知道为什么会这样。任何帮助将不胜感激。
function getCanvas() {
const canvas = document.createElement('canvas');
canvas.setAttribute('id', 'canv1');
const ctx = canvas.getContext('2d');
const imageObj1 = new Image();
imageObj1.src = 'https://s-media-cache-ak0.pinimg.com/236x/d7/b3/cf/d7b3cfe04c2dc44400547ea6ef94ba35.jpg';
imageObj1.addEventListener('load', (e) => {
const drawImage = (ctx as CanvasRenderingContext2D).drawImage(imageObj1, 33, 71, 104, 124, 21, 20, 87, 104);
// returns undefined
console.log('REMOVE-ME',drawImage);
});
// Nothing happens on the canvas
return canvas;
}
【问题讨论】:
标签: javascript reactjs canvas webrtc