LoginSignup
0
0

More than 3 years have passed since last update.

P5.js 日本語リファレンス(saveCanvas)

Last updated at Posted at 2020-06-12

このページでは「P5.js 日本語リファレンス」 の saveCanvas関数を説明します。

saveCanvas()

説明文

現在のキャンバスを画像として保存します。ブラウザはファイルをすぐに保存するか、ダイアログウィンドウでユーザーに次の操作を促します。

構文

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

saveCanvas([filename], [extention])

パラメタ

  • selectedCanvas

    p5.Element | HTMLCanvasElement:特定のhtml5キャンバスを表す変数(オプション)

  • filename

    String:(オプション)

  • extention

    String:'jpg'または 'png'(オプション)

例1

function setup() {
  let c = createCanvas(100, 100);
  background(255, 0, 0);

  // 背景色が赤色の画像をファイル名 myCanvas.jpg で保存する
  saveCanvas(c, 'myCanvas', 'jpg');
}

実行結果

例2

//この例は上記と同じ結果になることに注意してください
//キャンバスが指定されていない場合, メインキャンバスがデフォルトになります
function setup() {
  let c = createCanvas(100, 100);
  background(255, 0, 0);

  //以下のすべてが有効です
  saveCanvas(c,  'myCanvas',  'jpg');
  saveCanvas(c,  'myCanvas.jpg');

  // extention を省略すると png になります
  saveCanvas(c,  'myCanvas');

  // ファイル名を省略すると untitled.png になります
  saveCanvas(c);

  // ファイル名を省略すると untitled.png になります

  saveCanvas() ;}

実行結果

著作権

p5.js was created by Lauren McCarthy and is developed by a community of collaborators, with support from the Processing Foundation and NYU ITP. Identity and graphic design by Jerel Johnson.

ライセンス

Creative Commons(CC BY-NC-SA 4.0) に従います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0