screenshotTools.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. import { Texture } from "../Materials/Textures/texture.js";
  2. import { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture.js";
  3. import { FxaaPostProcess } from "../PostProcesses/fxaaPostProcess.js";
  4. import { Logger } from "./logger.js";
  5. import { Tools } from "./tools.js";
  6. import { DumpTools } from "./dumpTools.js";
  7. import { ApplyPostProcess } from "./textureTools.js";
  8. let screenshotCanvas = null;
  9. /**
  10. * Captures a screenshot of the current rendering
  11. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  12. * @param engine defines the rendering engine
  13. * @param camera defines the source camera
  14. * @param size This parameter can be set to a single number or to an object with the
  15. * following (optional) properties: precision, width, height. If a single number is passed,
  16. * it will be used for both width and height. If an object is passed, the screenshot size
  17. * will be derived from the parameters. The precision property is a multiplier allowing
  18. * rendering at a higher or lower resolution
  19. * @param successCallback defines the callback receives a single parameter which contains the
  20. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  21. * src parameter of an <img> to display it
  22. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  23. * Check your browser for supported MIME types
  24. * @param forceDownload force the system to download the image even if a successCallback is provided
  25. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  26. */
  27. export function CreateScreenshot(engine, camera, size, successCallback, mimeType = "image/png", forceDownload = false, quality) {
  28. const { height, width } = _GetScreenshotSize(engine, camera, size);
  29. if (!(height && width)) {
  30. Logger.Error("Invalid 'size' parameter !");
  31. return;
  32. }
  33. if (!screenshotCanvas) {
  34. screenshotCanvas = document.createElement("canvas");
  35. }
  36. screenshotCanvas.width = width;
  37. screenshotCanvas.height = height;
  38. const renderContext = screenshotCanvas.getContext("2d");
  39. const ratio = engine.getRenderWidth() / engine.getRenderHeight();
  40. let newWidth = width;
  41. let newHeight = newWidth / ratio;
  42. if (newHeight > height) {
  43. newHeight = height;
  44. newWidth = newHeight * ratio;
  45. }
  46. const offsetX = Math.max(0, width - newWidth) / 2;
  47. const offsetY = Math.max(0, height - newHeight) / 2;
  48. const scene = camera.getScene();
  49. if (scene.activeCamera !== camera) {
  50. CreateScreenshotUsingRenderTarget(engine, camera, size, (data) => {
  51. if (forceDownload) {
  52. const blob = new Blob([data]);
  53. Tools.DownloadBlob(blob);
  54. if (successCallback) {
  55. successCallback("");
  56. }
  57. }
  58. else if (successCallback) {
  59. successCallback(data);
  60. }
  61. }, mimeType, 1.0, engine.getCreationOptions().antialias, undefined, undefined, undefined, undefined, quality);
  62. }
  63. else {
  64. engine.onEndFrameObservable.addOnce(() => {
  65. const renderingCanvas = engine.getRenderingCanvas();
  66. if (renderContext && renderingCanvas) {
  67. renderContext.drawImage(renderingCanvas, offsetX, offsetY, newWidth, newHeight);
  68. }
  69. if (screenshotCanvas) {
  70. if (forceDownload) {
  71. Tools.EncodeScreenshotCanvasData(screenshotCanvas, undefined, mimeType, undefined, quality);
  72. if (successCallback) {
  73. successCallback("");
  74. }
  75. }
  76. else {
  77. Tools.EncodeScreenshotCanvasData(screenshotCanvas, successCallback, mimeType, undefined, quality);
  78. }
  79. }
  80. });
  81. }
  82. }
  83. /**
  84. * Captures a screenshot of the current rendering
  85. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  86. * @param engine defines the rendering engine
  87. * @param camera defines the source camera
  88. * @param size This parameter can be set to a single number or to an object with the
  89. * following (optional) properties: precision, width, height. If a single number is passed,
  90. * it will be used for both width and height. If an object is passed, the screenshot size
  91. * will be derived from the parameters. The precision property is a multiplier allowing
  92. * rendering at a higher or lower resolution
  93. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  94. * Check your browser for supported MIME types
  95. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  96. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  97. * to the src parameter of an <img> to display it
  98. */
  99. export function CreateScreenshotAsync(engine, camera, size, mimeType = "image/png", quality) {
  100. return new Promise((resolve, reject) => {
  101. CreateScreenshot(engine, camera, size, (data) => {
  102. if (typeof data !== "undefined") {
  103. resolve(data);
  104. }
  105. else {
  106. reject(new Error("Data is undefined"));
  107. }
  108. }, mimeType, undefined, quality);
  109. });
  110. }
  111. /**
  112. * Captures a screenshot of the current rendering for a specific size. This will render the entire canvas but will generate a blink (due to canvas resize)
  113. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  114. * @param engine defines the rendering engine
  115. * @param camera defines the source camera
  116. * @param width defines the expected width
  117. * @param height defines the expected height
  118. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  119. * Check your browser for supported MIME types
  120. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  121. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  122. * to the src parameter of an <img> to display it
  123. */
  124. export function CreateScreenshotWithResizeAsync(engine, camera, width, height, mimeType = "image/png", quality) {
  125. return new Promise((resolve) => {
  126. CreateScreenshot(engine, camera, { width: width, height: height }, () => {
  127. resolve();
  128. }, mimeType, true, quality);
  129. });
  130. }
  131. /**
  132. * Generates an image screenshot from the specified camera.
  133. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  134. * @param engine The engine to use for rendering
  135. * @param camera The camera to use for rendering
  136. * @param size This parameter can be set to a single number or to an object with the
  137. * following (optional) properties: precision, width, height, finalWidth, finalHeight. If a single number is passed,
  138. * it will be used for both width and height, as well as finalWidth, finalHeight. If an object is passed, the screenshot size
  139. * will be derived from the parameters. The precision property is a multiplier allowing
  140. * rendering at a higher or lower resolution
  141. * @param successCallback The callback receives a single parameter which contains the
  142. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  143. * src parameter of an <img> to display it
  144. * @param mimeType The MIME type of the screenshot image (default: image/png).
  145. * Check your browser for supported MIME types
  146. * @param samples Texture samples (default: 1)
  147. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  148. * @param fileName A name for for the downloaded file.
  149. * @param renderSprites Whether the sprites should be rendered or not (default: false)
  150. * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)
  151. * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)
  152. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  153. * @param customizeTexture An optional callback that can be used to modify the render target texture before taking the screenshot. This can be used, for instance, to enable camera post-processes before taking the screenshot.
  154. */
  155. export function CreateScreenshotUsingRenderTarget(engine, camera, size, successCallback, mimeType = "image/png", samples = 1, antialiasing = false, fileName, renderSprites = false, enableStencilBuffer = false, useLayerMask = true, quality, customizeTexture) {
  156. const { height, width, finalWidth, finalHeight } = _GetScreenshotSize(engine, camera, size);
  157. const targetTextureSize = { width, height };
  158. if (!(height && width)) {
  159. Logger.Error("Invalid 'size' parameter !");
  160. return;
  161. }
  162. const originalSize = { width: engine.getRenderWidth(), height: engine.getRenderHeight() };
  163. engine.setSize(width, height); // we need this call to trigger onResizeObservable with the screenshot width/height on all the subsystems that are observing this event and that needs to (re)create some resources with the right dimensions
  164. const scene = camera.getScene();
  165. // At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
  166. const texture = new RenderTargetTexture("screenShot", targetTextureSize, scene, false, false, 0, false, Texture.BILINEAR_SAMPLINGMODE, undefined, enableStencilBuffer, undefined, undefined, undefined, samples);
  167. texture.renderList = scene.meshes.slice();
  168. texture.samples = samples;
  169. texture.renderSprites = renderSprites;
  170. texture.activeCamera = camera;
  171. texture.forceLayerMaskCheck = useLayerMask;
  172. customizeTexture?.(texture);
  173. const renderWhenReady = () => {
  174. if (texture.isReadyForRendering() && camera.isReady(true)) {
  175. engine.onEndFrameObservable.addOnce(() => {
  176. if (finalWidth === width && finalHeight === height) {
  177. texture.readPixels(undefined, undefined, undefined, false).then((data) => {
  178. DumpTools.DumpData(width, height, data, successCallback, mimeType, fileName, true, undefined, quality);
  179. texture.dispose();
  180. });
  181. }
  182. else {
  183. ApplyPostProcess("pass", texture.getInternalTexture(), scene, undefined, undefined, undefined, finalWidth, finalHeight).then((texture) => {
  184. engine._readTexturePixels(texture, finalWidth, finalHeight, -1, 0, null, true, false, 0, 0).then((data) => {
  185. DumpTools.DumpData(finalWidth, finalHeight, data, successCallback, mimeType, fileName, true, undefined, quality);
  186. texture.dispose();
  187. });
  188. });
  189. }
  190. });
  191. texture.render(true);
  192. // re-render the scene after the camera has been reset to the original camera to avoid a flicker that could occur
  193. // if the camera used for the RTT rendering stays in effect for the next frame (and if that camera was different from the original camera)
  194. scene.incrementRenderId();
  195. scene.resetCachedMaterial();
  196. engine.setSize(originalSize.width, originalSize.height);
  197. camera.getProjectionMatrix(true); // Force cache refresh;
  198. scene.render();
  199. }
  200. else {
  201. setTimeout(renderWhenReady, 16);
  202. }
  203. };
  204. const renderToTexture = () => {
  205. // render the RTT
  206. scene.incrementRenderId();
  207. scene.resetCachedMaterial();
  208. renderWhenReady();
  209. };
  210. if (antialiasing) {
  211. const fxaaPostProcess = new FxaaPostProcess("antialiasing", 1.0, scene.activeCamera);
  212. texture.addPostProcess(fxaaPostProcess);
  213. // Async Shader Compilation can lead to none ready effects in synchronous code
  214. if (!fxaaPostProcess.getEffect().isReady()) {
  215. fxaaPostProcess.getEffect().onCompiled = () => {
  216. renderToTexture();
  217. };
  218. }
  219. // The effect is ready we can render
  220. else {
  221. renderToTexture();
  222. }
  223. }
  224. else {
  225. // No need to wait for extra resources to be ready
  226. renderToTexture();
  227. }
  228. }
  229. /**
  230. * Generates an image screenshot from the specified camera.
  231. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  232. * @param engine The engine to use for rendering
  233. * @param camera The camera to use for rendering
  234. * @param size This parameter can be set to a single number or to an object with the
  235. * following (optional) properties: precision, width, height. If a single number is passed,
  236. * it will be used for both width and height. If an object is passed, the screenshot size
  237. * will be derived from the parameters. The precision property is a multiplier allowing
  238. * rendering at a higher or lower resolution
  239. * @param mimeType The MIME type of the screenshot image (default: image/png).
  240. * Check your browser for supported MIME types
  241. * @param samples Texture samples (default: 1)
  242. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  243. * @param fileName A name for for the downloaded file.
  244. * @param renderSprites Whether the sprites should be rendered or not (default: false)
  245. * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)
  246. * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)
  247. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  248. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  249. * to the src parameter of an <img> to display it
  250. */
  251. export function CreateScreenshotUsingRenderTargetAsync(engine, camera, size, mimeType = "image/png", samples = 1, antialiasing = false, fileName, renderSprites = false, enableStencilBuffer = false, useLayerMask = true, quality) {
  252. return new Promise((resolve, reject) => {
  253. CreateScreenshotUsingRenderTarget(engine, camera, size, (data) => {
  254. if (typeof data !== "undefined") {
  255. resolve(data);
  256. }
  257. else {
  258. reject(new Error("Data is undefined"));
  259. }
  260. }, mimeType, samples, antialiasing, fileName, renderSprites, enableStencilBuffer, useLayerMask, quality);
  261. });
  262. }
  263. /**
  264. * Gets height and width for screenshot size
  265. * @param engine
  266. * @param camera
  267. * @param size
  268. * @private
  269. */
  270. function _GetScreenshotSize(engine, camera, size) {
  271. let height = 0;
  272. let width = 0;
  273. let finalWidth = 0;
  274. let finalHeight = 0;
  275. //If a size value defined as object
  276. if (typeof size === "object") {
  277. const precision = size.precision
  278. ? Math.abs(size.precision) // prevent GL_INVALID_VALUE : glViewport: negative width/height
  279. : 1;
  280. //If a width and height values is specified
  281. if (size.width && size.height) {
  282. height = size.height * precision;
  283. width = size.width * precision;
  284. }
  285. //If passing only width, computing height to keep display canvas ratio.
  286. else if (size.width && !size.height) {
  287. width = size.width * precision;
  288. height = Math.round(width / engine.getAspectRatio(camera));
  289. }
  290. //If passing only height, computing width to keep display canvas ratio.
  291. else if (size.height && !size.width) {
  292. height = size.height * precision;
  293. width = Math.round(height * engine.getAspectRatio(camera));
  294. }
  295. else {
  296. width = Math.round(engine.getRenderWidth() * precision);
  297. height = Math.round(width / engine.getAspectRatio(camera));
  298. }
  299. //If a finalWidth and finalHeight values is specified
  300. if (size.finalWidth && size.finalHeight) {
  301. finalHeight = size.finalHeight;
  302. finalWidth = size.finalWidth;
  303. }
  304. //If passing only finalWidth, computing finalHeight to keep display canvas ratio.
  305. else if (size.finalWidth && !size.finalHeight) {
  306. finalWidth = size.finalWidth;
  307. finalHeight = Math.round(finalWidth / engine.getAspectRatio(camera));
  308. }
  309. //If passing only finalHeight, computing finalWidth to keep display canvas ratio.
  310. else if (size.finalHeight && !size.finalWidth) {
  311. finalHeight = size.finalHeight;
  312. finalWidth = Math.round(finalHeight * engine.getAspectRatio(camera));
  313. }
  314. else {
  315. finalWidth = width;
  316. finalHeight = height;
  317. }
  318. }
  319. //Assuming here that "size" parameter is a number
  320. else if (!isNaN(size)) {
  321. height = size;
  322. width = size;
  323. finalWidth = size;
  324. finalHeight = size;
  325. }
  326. // When creating the image data from the CanvasRenderingContext2D, the width and height is clamped to the size of the _gl context
  327. // On certain GPUs, it seems as if the _gl context truncates to an integer automatically. Therefore, if a user tries to pass the width of their canvas element
  328. // and it happens to be a float (1000.5 x 600.5 px), the engine.readPixels will return a different size array than context.createImageData
  329. // to resolve this, we truncate the floats here to ensure the same size
  330. if (width) {
  331. width = Math.floor(width);
  332. }
  333. if (height) {
  334. height = Math.floor(height);
  335. }
  336. if (finalWidth) {
  337. finalWidth = Math.floor(finalWidth);
  338. }
  339. if (finalHeight) {
  340. finalHeight = Math.floor(finalHeight);
  341. }
  342. return { height: height | 0, width: width | 0, finalWidth: finalWidth | 0, finalHeight: finalHeight | 0 };
  343. }
  344. /**
  345. * Class containing a set of static utilities functions for screenshots
  346. */
  347. export const ScreenshotTools = {
  348. /**
  349. * Captures a screenshot of the current rendering
  350. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  351. * @param engine defines the rendering engine
  352. * @param camera defines the source camera
  353. * @param size This parameter can be set to a single number or to an object with the
  354. * following (optional) properties: precision, width, height. If a single number is passed,
  355. * it will be used for both width and height. If an object is passed, the screenshot size
  356. * will be derived from the parameters. The precision property is a multiplier allowing
  357. * rendering at a higher or lower resolution
  358. * @param successCallback defines the callback receives a single parameter which contains the
  359. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  360. * src parameter of an <img> to display it
  361. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  362. * Check your browser for supported MIME types
  363. * @param forceDownload force the system to download the image even if a successCallback is provided
  364. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  365. */
  366. CreateScreenshot,
  367. /**
  368. * Captures a screenshot of the current rendering
  369. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  370. * @param engine defines the rendering engine
  371. * @param camera defines the source camera
  372. * @param size This parameter can be set to a single number or to an object with the
  373. * following (optional) properties: precision, width, height. If a single number is passed,
  374. * it will be used for both width and height. If an object is passed, the screenshot size
  375. * will be derived from the parameters. The precision property is a multiplier allowing
  376. * rendering at a higher or lower resolution
  377. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  378. * Check your browser for supported MIME types
  379. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  380. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  381. * to the src parameter of an <img> to display it
  382. */
  383. CreateScreenshotAsync,
  384. /**
  385. * Captures a screenshot of the current rendering for a specific size. This will render the entire canvas but will generate a blink (due to canvas resize)
  386. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  387. * @param engine defines the rendering engine
  388. * @param camera defines the source camera
  389. * @param width defines the expected width
  390. * @param height defines the expected height
  391. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  392. * Check your browser for supported MIME types
  393. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  394. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  395. * to the src parameter of an <img> to display it
  396. */
  397. CreateScreenshotWithResizeAsync,
  398. /**
  399. * Generates an image screenshot from the specified camera.
  400. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  401. * @param engine The engine to use for rendering
  402. * @param camera The camera to use for rendering
  403. * @param size This parameter can be set to a single number or to an object with the
  404. * following (optional) properties: precision, width, height. If a single number is passed,
  405. * it will be used for both width and height. If an object is passed, the screenshot size
  406. * will be derived from the parameters. The precision property is a multiplier allowing
  407. * rendering at a higher or lower resolution
  408. * @param successCallback The callback receives a single parameter which contains the
  409. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  410. * src parameter of an <img> to display it
  411. * @param mimeType The MIME type of the screenshot image (default: image/png).
  412. * Check your browser for supported MIME types
  413. * @param samples Texture samples (default: 1)
  414. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  415. * @param fileName A name for for the downloaded file.
  416. * @param renderSprites Whether the sprites should be rendered or not (default: false)
  417. * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)
  418. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  419. */
  420. CreateScreenshotUsingRenderTarget,
  421. /**
  422. * Generates an image screenshot from the specified camera.
  423. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  424. * @param engine The engine to use for rendering
  425. * @param camera The camera to use for rendering
  426. * @param size This parameter can be set to a single number or to an object with the
  427. * following (optional) properties: precision, width, height. If a single number is passed,
  428. * it will be used for both width and height. If an object is passed, the screenshot size
  429. * will be derived from the parameters. The precision property is a multiplier allowing
  430. * rendering at a higher or lower resolution
  431. * @param mimeType The MIME type of the screenshot image (default: image/png).
  432. * Check your browser for supported MIME types
  433. * @param samples Texture samples (default: 1)
  434. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  435. * @param fileName A name for for the downloaded file.
  436. * @param renderSprites Whether the sprites should be rendered or not (default: false)
  437. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  438. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  439. * to the src parameter of an <img> to display it
  440. */
  441. CreateScreenshotUsingRenderTargetAsync,
  442. };
  443. /**
  444. * This will be executed automatically for UMD and es5.
  445. * If esm dev wants the side effects to execute they will have to run it manually
  446. * Once we build native modules those need to be exported.
  447. * @internal
  448. */
  449. const initSideEffects = () => {
  450. // References the dependencies.
  451. Tools.CreateScreenshot = CreateScreenshot;
  452. Tools.CreateScreenshotAsync = CreateScreenshotAsync;
  453. Tools.CreateScreenshotUsingRenderTarget = CreateScreenshotUsingRenderTarget;
  454. Tools.CreateScreenshotUsingRenderTargetAsync = CreateScreenshotUsingRenderTargetAsync;
  455. };
  456. initSideEffects();
  457. //# sourceMappingURL=screenshotTools.js.map