--- title: CanvasRenderingContext2D.restore() slug: Web/API/CanvasRenderingContext2D/restore translation_of: Web/API/CanvasRenderingContext2D/restore ---
Метод CanvasRenderingContext2D.restore() восстанавливает предварительно сохранённое состояние канваса из стека. Если состояние ранее не сохранялось, то метод ничего не делает.
Fore more information about the drawing state, see {{domxref("CanvasRenderingContext2D.save()")}}.
void ctx.restore();
This example uses the save() method to save the default state and restore() to restore it later, so that you are able to draw a rect with the default state later.
<canvas id="canvas"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// Save the default state
ctx.save();
ctx.fillStyle = 'green';
ctx.fillRect(10, 10, 100, 100);
// Restore the default state
ctx.restore();
ctx.fillRect(150, 40, 100, 100);
{{ EmbedLiveSample('Restoring_a_saved_state', 700, 180) }}
{{Compat}}