Skip to content

Commit

Permalink
Canvas buffer is cleared when setting width/height (#34225)
Browse files Browse the repository at this point in the history
* Canvas buffer is cleared when setting width/height

* Apply suggestions from code review

---------

Co-authored-by: Hamish Willee <[email protected]>
  • Loading branch information
Josh-Cena and hamishwillee authored Jun 17, 2024
1 parent 565c455 commit c16ab79
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions files/en-us/web/api/htmlcanvaselement/height/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ attribute of the {{HTMLElement("canvas")}} element interpreted in CSS pixels. Wh
attribute is not specified, or if it is set to an invalid value, like a negative, the
default value of `150` is used.

When the `height` property is set the drawing buffer is always reset to blank — this is true for all context types, and even when the height is set to the same value. If you need to restore the previous content, you can save it via {{domxref("CanvasRenderingContext2D.getImageData()")}} and restore it via {{domxref("CanvasRenderingContext2D.putImageData()")}}.

This is one of the two properties, the other being
{{domxref("HTMLCanvasElement.width")}}, that controls the size of the canvas.

Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/api/htmlcanvaselement/width/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ attribute of the {{HTMLElement("canvas")}} element interpreted in CSS pixels. Wh
attribute is not specified, or if it is set to an invalid value, like a negative, the
default value of `300` is used.

When the `width` property is set the drawing buffer is always reset to blank — this is true for all context types, and even when the width is set to the same value. If you need to restore the previous content, you can save it via {{domxref("CanvasRenderingContext2D.getImageData()")}} and restore it via {{domxref("CanvasRenderingContext2D.putImageData()")}}.

This is one of the two properties, the other being
{{domxref("HTMLCanvasElement.height")}}, that controls the size of the canvas.

Expand Down

0 comments on commit c16ab79

Please sign in to comment.