Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
Can anyone tell me how to save a canvas image with the background color?

window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
ctx.fillStyle = "black";
ctx.fillRect(180, 180, 40, 40);
}

function saveWithBackground(canvas) {
var link = document.createElement("a");
link.href = canvas.toDataURL();
link.download = "download.jpg";
link.click();
}
#canvas {
border: 1px solid black;
background-color: red;
}
<canvas id="canvas" width="400" height="400"></canvas>
<button onclick="saveWithBackground(document.getElementById('canvas'))">Save</button>
but this does not save the image with the background.

Can someone tell me how to save it with background color?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you should set the background in canvas.

window.onload = function () {
    var ctx = document.getElementById("canvas").getContext("2d");
    ctx.fillStyle = "red";
    ctx.fillRect(0, 0, 400, 400);
    ctx.fillStyle = "black";
    ctx.fillRect(180, 180, 40, 40);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda