0

尝试运行此功能,但没有输出

const fs = require("fs");
const { createCanvas, loadImage } = require("canvas");
const console = require("console");
const canvas = createCanvas(1000, 1000); 
const ctx = canvas.getContext("2d");


const drawLayer = async () => {
   const image = await loadImage("./batmanpfp.png");
   ctx.drawImage(image, 0, 0, 1000, 1000);
   console.log("this ran.");5
};

drawLayer( );

OUTPUT(试了很多次,没有输出)

PS C:\Users\USER\Desktop\NFT2> node index.js
PS C:\Users\USER\Desktop\NFT2> node index.js
PS C:\Users\USER\Desktop\NFT2> node index.js
PS C:\Users\USER\Desktop\NFT2> node index.js
PS C:\Users\USER\Desktop\NFT2> node index.js
PS C:\Users\USER\Desktop\NFT2> node index.js
PS C:\Users\USER\Desktop\NFT2> node index.js

我不是程序员,从这里学习: https ://www.youtube.com/watch?v=3c2EFpCr_vY&list=PLvfQp12V0hS3AVImYdMNfkdvRtZEe7xqY

可能的问题: 我在 const image = await loadImage("./batmanpfp.png"); 中犯了错误吗?因为我不知道“./”的意义,但我调用的文件在我的根目录中(根文件夹称为 NFT)

4

1 回答 1

0

./ 引用文件所在的相同目录/文件夹。您可以将其视为当前目录/文件夹。

于 2021-09-11T20:48:39.200 回答