Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
Cannot Draw Canvas Image On Image's Load

I have a canvas and I wish to draw an icon on it. I'm aware you have to wait for the image to load before attempting to draw the image however nothing I've tried has worked.

I've attempted to use the full image URL (protocol, domain, and path), I've moved everything around, nothing has worked.

I've been Googling around for the better part of an hour and pretty much every solution involves making sure that the image loads first.

Here are a couple of snippets of what I have.

const image = new Image()
image.addEventListener('load', _ => {
    addImage(canvas, image, coords)
})
image.src = '/images/image-location.svg'
function addImage(canvas, image, coords) {
    const ctx = canvas.getContext('2d')
    ctx.save()
    ctx.drawImage(image, 0, 0, image.width, image.height, ...coords, 50, 50)
    ctx.restore()
}

I threw a console.log within the event listener just to make sure it was firing and it does indeed fire. I even logged inside addImage and it definitely gets that far.

What is the solution to this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I figured out the issue I was having here. I needed to add width/height attributes to the SVG element I was using as an image.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda