Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
Svelte - Create Image() object for canvas background from local image

I would like to create a background image pattern for a canvas in my svelte application. I am using the following code to create the pattern but it creates a black canvas.

let image = new Image();
image.src = 'images/background.png'
ctx.fillStyle = ctx.createPattern(image, 'repeat'); 
ctx.fillRect(0, 0, canvas.width, canvas.height)

The image path is public/images/background.png

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You probably have to wait for the image to load, otherwise there is nothing to draw to the canvas. E.g.

const image = new Image();
image.src = 'images/background.png'
image.onload = () => {
    ctx.fillStyle = ctx.createPattern(image, 'repeat'); 
    ctx.fillRect(0, 0, canvas.width, canvas.height)
};

REPL example

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!