原生并且使用react-native-canvas绘制本地图像时遇到问题。我的代码如下:
export default class App extends React.Component {
handleCanvas = (canvas) => {
const image = new CanvasImage(canvas);
canvas.width = 100;
canvas.height = 100;
const context = canvas.getContext('2d');
image.src = './dys.jpeg'; //'https://image.freepik.com/free-vector/unicorn-background-design_1324-79.jpg';
image.addEventListener('load', () => {
console.log('image is loaded');
context.drawImage(image, 0, 0, 1000, 1000);
});
}
render() {
return (
<Canvas ref={this.handleCanvas}/>
);
}
}
请注意,wen image.source来自网络,例如&#39; https://image.freepik.com/free-vector/unicorn-background-design_1324-79.jpg&#39;一切顺利。
有人可以帮助我在上面的代码中为image.src设置本地路径吗?
谢谢你, 此致 卓然