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

389
Visualizações
How do I fill the transparent area inside an image using javascript?

I added a white border to a PNG image with Konvajs example

konvajs link

I want to turn the transparent area inside the white border to white. So I want to paint the windows of the car white. (Red areas are transparent.)

example

Expected result: result

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

0

One thing you could maybe do is converting you image to a SVG.

You would then have a path for your car windows with some class. You could afterward change the style of the SVG class in JS.

enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório

0

To fix the problem you want background color white. As your link there are a function called removeTransparency it makes the image background color white see it.

      // make all pixels opaque 100% (except pixels that 100% transparent)
      function removeTransparency(canvas) {
        var ctx = canvas.getContext('2d');

        var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
        var nPixels = imageData.data.length;
        for (var i = 3; i < nPixels; i += 4) {
          if (imageData.data[i] > 0) {
            imageData.data[i] = 255;
          }
        }
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        ctx.putImageData(imageData, 0, 0);
        return canvas;
      }
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