DownloadTexture.jslib 780 B

123456789101112131415161718192021222324252627
  1. var DownloadTexture = {
  2. DownloadWebGLTexture: function(img, size, name, ext) {
  3. console.log(size);
  4. var binary = '';
  5. for (var i = 0; i < size; i++)
  6. binary += String.fromCharCode(HEAPU8[img + i]);
  7. var filename = UTF8ToString(name);
  8. var fileext = UTF8ToString(ext);
  9. if(fileext == ".png")
  10. var dataUrl = 'data:image/png;base64,' + btoa(binary);
  11. else if(fileext == ".jpeg")
  12. var dataUrl = 'data:image/jpeg;base64,' + btoa(binary);
  13. //download file
  14. var link = document.createElement("a");
  15. link.download = filename + fileext;
  16. link.href = dataUrl;
  17. document.body.appendChild(link);
  18. link.click();
  19. document.body.removeChild(link);
  20. delete link;
  21. },
  22. };
  23. mergeInto(LibraryManager.library, DownloadTexture);