Skip to main content
closePath method

Closes the current subpath and starts a new subpath that has a start point that is equal to the end of the closed subpath.

HTML Canvas 2D Context, Section 9 Internet Explorer 9

Syntax

var retval = CanvasRenderingContext2D.closePath();

Parameters

This method has no parameters.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Standards information

Remarks

Be aware that CanvasRenderingContext2D represents a canvas rendering 2D context object, as shown in the following example.

Examples

The following code example shows how the closePath method closes a path.


<!DOCTYPE html>
<html>

<head>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  <title>Canvas closePath Example</title>
</head>

<body onload="closeDemo();">
  <canvas id="demo" width="300" height="300"></canvas>
  <script>
    function closeDemo() {
      var canvas = document.getElementById("demo")
      var ctx = canvas.getContext('2d');        
			
      ctx.lineWidth="3";
      ctx.strokeStyle="blue";  
      ctx.beginPath();                    
      ctx.moveTo(0, 0);
      ctx.lineTo(150, 150);
      ctx.lineTo(200, 150);
      ctx.stroke();
      ctx.closePath(); // closePath() called here.
      ctx.moveTo(0, 0);
      ctx.lineTo(50, 150);         
      ctx.stroke();                               
    } // closeDemo
  </script>
</body>

</html>

See also

CanvasRenderingContext2D
beginPath

 

 

Send comments about this topic to Microsoft

Build date: 11/28/2012