userJS
userJS

Reputation: 129

How to download an image object from webgl/javascript

I have a directory with 100 images. I need a copy of them in various folders along with other information that I download from webgl. Hence I want to upload them onto the browser and download them again (hope that isn't stupid)

Here is my code:

var imagefile = model.features[cIndex].imageName.substring(model.features[cIndex].imageName.lastIndexOf('/')+1);
var image = new Image();
image.src = model.imageDirectory + imagefile;
image.onload = function() {
console.info("Read \""+image.src + "\"...Done");
}
image.onerror = function() {
var message = "Unable to open \"" + image.src + "\".";
console.error(message);
alert(message);
}

var data = image.src;

zip.file('image_RH_Original' + cIndex +'.png', data , {base64: true}); 

Is this wrong? How to I do something similar to "toDataURL" for the image object?

Upvotes: 1

Views: 594

Answers (1)

WacławJasper
WacławJasper

Reputation: 3364

toDataURL is a method of canvas, and webgl draws to a canvas. So just call canvas.toDataURL(). Probably need to set preserveDrawingBuffer to true as well.

Upvotes: 1

Related Questions