Load JPEG from URL into a texture in vtk.js

I have searched the vtk.js API and examples and I am unable to find out how to load a vtkTexture from a JPEG image retrieved from a URL. Similar to vtkJPEGReader in standard VTK. Any help would be appreciated.

const img = new Image();
img.src = 'http://url/to/your/image.jpg';

const texture = vtkTexture.newInstance();
texture.setImage(img);

Thanks Sebastien! That was much simpler than I thought! I am really excited about using VTK.js and will try to help contribute to the examples when I can.

1 Like


Hello, Sebastien Jourdain. In VTK development, I failed to use JPEG in URL to do texture. can’t show it!

I don’t think you can add a texture to a set of lines. You need a surface/box to be able to see your texture.

Can you recommend a sample code for me? Thank you very much! When you come to Nanjing, China, you can contact me and take you to eat the most famous Chinese food in Nanjing! Would you please give me an im ID or email? My email is agiles@139.com .

But I don’t understand what you want to do. You seems to have a vtkImageData and you want to do something with a texture but I have no clue what that could be.

Do you have the ID number of line? I’d like to add it to facilitate communication.my id : 13913043322