Die fill-Methode

Die Methode fill füllt eine Form, die mit den Methoden lineTo, rect, arc usw. gezeichnet wurde.

Syntax

javascriptKontext.fill();

Beispiel

Lassen Sie uns ein Quadrat zeichnen und es mit fill füllen:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');

ctx.beginPath();
ctx.moveTo(50, 50);
ctx.lineTo(150, 50);
ctx.lineTo(150, 150);
ctx.lineTo(50, 150);
ctx.fill();

Результат:

Siehe auch

  • die Eigenschaft fillStyle,
    die die Füllfarbe festlegt
  • die Methode stroke,
    die einen Umriss erstellt