舞台

4. 画布

4.4. 画布存为图像


saveCanvas()

示例:

▶️运行示例代码



function setup(){
  createCanvas(100,100);
  background('#ff0000');
  saveCanvas('myCanvas', 'jpg');
};
舞台区显示的画布内容如下:


Description

Save the current canvas as an image. The browser will either save the file immediately, or prompt the user with a dialogue window.

Syntax

saveCanvas(selectedCanvas, [filename], [extension])
saveCanvas([filename], [extension])

Parameters

  • selectedCanvas
     
    p5.Element|HTMLCanvasElement: 

    a variable representing a specific html5 canvas (optional)

  • filename
     
    String: (Optional)
  • extension
     
    String: 

    'jpg' or 'png'

     (Optional)