I am looking to save a PNG bitstream from a WebGL div.
The 3DMol viewer has a function that converts a WebGL view to PNG.
http://3dmol.csb.pitt.edu/doc/$3Dmol.GLViewer.html#png
It returns the PNG in bytes. How can I capture it and save to a file?
Click on the button to see the function perform.
let container = jQuery("#container-01");
let config = {backgroundColor: 'white'};
let theViewer = $3Dmol.createViewer(container, config);
$3Dmol.download("pdb:1DFJ", theViewer, {multimodel: true, frames: true}, function () {
theViewer.setStyle({}, {cartoon: {color: "spectrum"}});
theViewer.zoomTo();
theViewer.render();
}
);
$('#pngClick').click(function(){
theViewer.pngURI();
console.log('Clicked');
});
.mol-container {
width: 60%;
height: 400px;
position: relative;
}
<html>
<head>
<script src="http://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script>
</head>
<body>
<button id="pngClick">PNG</button>
<div id="container-01" class="mol-container"/>
</body>
</html>