UNPKG

cornerstone-web-image-loader

Version:
85 lines (62 loc) 2.21 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>arrayBufferToImage.js - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <h2><a href="index.html">Home</a></h2> </nav> <div id="main"> <h1 class="page-title">arrayBufferToImage.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/** * Convert array buffer to image. Returns a promise that resolves to an Image object for the bytes in arrayBuffer * * @param arrayBuffer - arrayBuffer with bytes for a web image (e.g. JPEG, PNG, etc) * @returns {Promise} Promise that resolves to an Image object */ export default function (arrayBuffer) { return new Promise((resolve, reject) => { const image = new Image(); const arrayBufferView = new Uint8Array(arrayBuffer); const blob = new Blob([arrayBufferView]); const urlCreator = window.URL || window.webkitURL; const imageUrl = urlCreator.createObjectURL(blob); image.src = imageUrl; image.onload = () => { resolve(image); urlCreator.revokeObjectURL(imageUrl); }; image.onerror = (error) => { urlCreator.revokeObjectURL(imageUrl); reject(error); }; }); } </code></pre> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>