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

68
Visualizações
Load array of images in Canvas

I want to load an array of images to canvas but don't know how to achieve it. I would appreciate it if I could get some pointers on how I can achieve it. I am using class-based component on React.

My Code:

drawCanvas(img, prevProps) {

const node = this.canvasRef.current;
const context = node.getContext("2d");


context.drawImage(img, 0, 0);
}

// imgArray = [image1, image2, image3]

componentDidUpdate(prevProps) {

  const imageArray = Array.from(imgArray).map((image) => image)

  console.log(imageArray)
  
  var img = new Image();
  img.src = this.props.image;
  img.onload = () => this.drawCanvas(img, prevProps);
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

None of this really involves React at all, other than you need to get a hold of the canvas reference, which you're doing.

If you already have the array of image objects, it's actually pretty straightforward. Just call drawImage() for each image in the array. You'll probably want to clear before you start drawing them, so the last ones don't bleed through and create weirdness.

context.clearRect(0, 0, canvas.width, canvas.height);
imageArray.forEach(image => {
  context.drawImage(image, 0, 0);
});

And that's it. Pretty straightforward.

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