显示从 Javascript 到 Processing.js canvas 的图像

Displaying image from Javascript to Processing.js canvas

因此,我正在尝试通过 Javascript 函数以编程方式将图像添加到我的 canvas:

    // Spawn function
    var spawnWrapper = function() {
        myCanvas = Processing.getInstanceById('mycanvas');
        // myCanvas.ellipse(50,50,50,50); // works fine here too
        myImage = myCanvas.loadImage('pegman.png');
        myCanvas.image(myImage,0,0);
    };

控制台中相同的连续调用有效: 此外,控制台上没有提到任何错误。

我真的被困在那里,非常感谢任何帮助;-)

我怀疑您可能遗漏了 preload directive

This directive regulates image preloading, which is required when using loadImage() or requestImage() in a sketch. Using this directive will preload all images indicated between quotes, and comma separated if multiple images are used, so that they will be ready for use when the sketch begins running.

希望对您有所帮助。我很好奇您为什么使用 processing.js 而不是 P5.js

祝你好运。