Apply css class to go.Picture


I am creating go.Picture to be displayed as images for the nodes based on base64 encoded images:

let picture = new go.Picture();
let base64picture = document.createElement("img");
base64picture.src = base64EncodedImageSrc;
picture.element = base64picture;

Now I would like to apply a css class in order to show the image in gray-scale.
I’ve tried several ways (.className, $(...).addClass()) of adding the class to the base64picture element but they have no effect.
Could you point me into the right direction how I could apply some css to the go.Picture?

Best regards,

I believe that is correct – the image is not rendered by the HTMLImageElement, so CSS cannot be applied.

I’ll see if there is a way to achieve what you want, but I suspect the answer is no.

Sorry, since we use the HTML Canvas’ method for drawing the image onto the canvas, it cannot be decorated with CSS.

You can take a base64 image and draw it to your own canvas, and then do whatever compositing/pixel manipulation you want on that canvas, and use that Canvas as the go.Picture source.


Note that I put the compositing canvas in the DOM, but this is not a requirement, its just to demonstrate visually what’s going on.

drawing my own canvas seems to work, thanks for the suggestion!