Fabricjs - setBackgroundImage to Empty URL causes null reference error in _setWidthHeight

StackOverflow https://stackoverflow.com/questions/23256281

  •  08-07-2023
  •  | 
  •  

Frage

I found an article that explained how to clear the background of a fabric canvas...

canvas.setBackgroundImage('', canvas.renderAll.bind(canvas));

I have built an online design tool utilizing Fabricjs 1.4.4 and have incorporated quite a bit of functionality but for the life of me I cannot figure out what I am doing wrong here. I can set the canvas to an actual image url and it displays correctly, but when I used the suggested code to REMOVE the background image (shown above) I get a javascript error in Fabric.js:

Unhandled exception at line 16045, column 7 in .../fabric.js

0x800a138f - JavaScript runtime error: Unable to get property 'width' of undefined or null reference.

The line referenced is from the _setWidthHeight method

Am I doing something wrong? This seems like it should be fairly straight forward but I cannot remove the background image...whether one exists or not.

K-Dev

War es hilfreich?

Lösung

If setting the background image to an empty string doesn't work try and set it to 0.

canvas.setBackgroundImage(0, canvas.renderAll.bind(canvas));

This works for us. regards, Benick

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top