What's problem you are encountering?
I'm trying to write a JavaScript function to download a variable's content as a .bmp image, but every time I run the function, the file gets corrupted. What have you tried that didn't work?
I've tried a few diffrent methods. Here's the one I've got right now:
function download(filename, data){
var blob = new Blob([data], {type: "data:image/bmp;base64"});
saveAs(blob, filename + ".bmp");
}
if (filename.endsWith('.bmp'))
filename = filename.substr(0, filename.lastIndexOf('.bmp'));
var lnk = document.createElement('a');
lnk.href = (URL||webkitURL).createObjectURL(new Blob([data]));
lnk.download = filename + '.bmp';
lnk.click();
and see if that doesn't work.
It could also be that you're feeding it the wrong kind of data. What's the value of the variable? Is it a list of pixels?