forked from BabylonJS/Babylon.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshotTools.ts
591 lines (553 loc) · 28.1 KB
/
screenshotTools.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
/* eslint-disable @typescript-eslint/naming-convention */
import type { Camera } from "../Cameras/camera";
import { Texture } from "../Materials/Textures/texture";
import { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
import { FxaaPostProcess } from "../PostProcesses/fxaaPostProcess";
import { Constants } from "../Engines/constants";
import { Logger } from "./logger";
import { Tools } from "./tools";
import type { IScreenshotSize } from "./interfaces/screenshotSize";
import { DumpTools } from "./dumpTools";
import type { Nullable } from "../types";
import { ApplyPostProcess } from "./textureTools";
import type { Engine } from "../Engines/engine";
let screenshotCanvas: Nullable<HTMLCanvasElement> = null;
/**
* Captures a screenshot of the current rendering
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
* @param engine defines the rendering engine
* @param camera defines the source camera
* @param size This parameter can be set to a single number or to an object with the
* following (optional) properties: precision, width, height. If a single number is passed,
* it will be used for both width and height. If an object is passed, the screenshot size
* will be derived from the parameters. The precision property is a multiplier allowing
* rendering at a higher or lower resolution
* @param successCallback defines the callback receives a single parameter which contains the
* screenshot as a string of base64-encoded characters. This string can be assigned to the
* src parameter of an <img> to display it
* @param mimeType defines the MIME type of the screenshot image (default: image/png).
* Check your browser for supported MIME types
* @param forceDownload force the system to download the image even if a successCallback is provided
* @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.
*/
export function CreateScreenshot(
engine: Engine,
camera: Camera,
size: IScreenshotSize | number,
successCallback?: (data: string) => void,
mimeType = "image/png",
forceDownload = false,
quality?: number
): void {
const { height, width } = _GetScreenshotSize(engine, camera, size);
if (!(height && width)) {
Logger.Error("Invalid 'size' parameter !");
return;
}
if (!screenshotCanvas) {
screenshotCanvas = document.createElement("canvas");
}
screenshotCanvas.width = width;
screenshotCanvas.height = height;
const renderContext = screenshotCanvas.getContext("2d");
const ratio = engine.getRenderWidth() / engine.getRenderHeight();
let newWidth = width;
let newHeight = newWidth / ratio;
if (newHeight > height) {
newHeight = height;
newWidth = newHeight * ratio;
}
const offsetX = Math.max(0, width - newWidth) / 2;
const offsetY = Math.max(0, height - newHeight) / 2;
const scene = camera.getScene();
if (scene.activeCamera !== camera) {
CreateScreenshotUsingRenderTarget(
engine,
camera,
size,
(data) => {
if (forceDownload) {
const blob = new Blob([data]);
Tools.DownloadBlob(blob);
if (successCallback) {
successCallback("");
}
} else if (successCallback) {
successCallback(data);
}
},
mimeType,
1.0,
engine.getCreationOptions().antialias,
undefined,
undefined,
undefined,
undefined,
quality
);
} else {
engine.onEndFrameObservable.addOnce(() => {
const renderingCanvas = engine.getRenderingCanvas();
if (renderContext && renderingCanvas) {
renderContext.drawImage(renderingCanvas, offsetX, offsetY, newWidth, newHeight);
}
if (screenshotCanvas) {
if (forceDownload) {
Tools.EncodeScreenshotCanvasData(screenshotCanvas, undefined, mimeType, undefined, quality);
if (successCallback) {
successCallback("");
}
} else {
Tools.EncodeScreenshotCanvasData(screenshotCanvas, successCallback, mimeType, undefined, quality);
}
}
});
}
}
/**
* Captures a screenshot of the current rendering
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
* @param engine defines the rendering engine
* @param camera defines the source camera
* @param size This parameter can be set to a single number or to an object with the
* following (optional) properties: precision, width, height. If a single number is passed,
* it will be used for both width and height. If an object is passed, the screenshot size
* will be derived from the parameters. The precision property is a multiplier allowing
* rendering at a higher or lower resolution
* @param mimeType defines the MIME type of the screenshot image (default: image/png).
* Check your browser for supported MIME types
* @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.
* @returns screenshot as a string of base64-encoded characters. This string can be assigned
* to the src parameter of an <img> to display it
*/
export function CreateScreenshotAsync(engine: Engine, camera: Camera, size: IScreenshotSize | number, mimeType = "image/png", quality?: number): Promise<string> {
return new Promise((resolve, reject) => {
CreateScreenshot(
engine,
camera,
size,
(data) => {
if (typeof data !== "undefined") {
resolve(data);
} else {
reject(new Error("Data is undefined"));
}
},
mimeType,
undefined,
quality
);
});
}
/**
* 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)
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
* @param engine defines the rendering engine
* @param camera defines the source camera
* @param width defines the expected width
* @param height defines the expected height
* @param mimeType defines the MIME type of the screenshot image (default: image/png).
* Check your browser for supported MIME types
* @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.
* @returns screenshot as a string of base64-encoded characters. This string can be assigned
* to the src parameter of an <img> to display it
*/
export function CreateScreenshotWithResizeAsync(engine: Engine, camera: Camera, width: number, height: number, mimeType = "image/png", quality?: number): Promise<void> {
return new Promise((resolve) => {
CreateScreenshot(
engine,
camera,
{ width: width, height: height },
() => {
resolve();
},
mimeType,
true,
quality
);
});
}
/**
* Generates an image screenshot from the specified camera.
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
* @param engine The engine to use for rendering
* @param camera The camera to use for rendering
* @param size This parameter can be set to a single number or to an object with the
* following (optional) properties: precision, width, height, finalWidth, finalHeight. If a single number is passed,
* it will be used for both width and height, as well as finalWidth, finalHeight. If an object is passed, the screenshot size
* will be derived from the parameters. The precision property is a multiplier allowing
* rendering at a higher or lower resolution
* @param successCallback The callback receives a single parameter which contains the
* screenshot as a string of base64-encoded characters. This string can be assigned to the
* src parameter of an <img> to display it
* @param mimeType The MIME type of the screenshot image (default: image/png).
* Check your browser for supported MIME types
* @param samples Texture samples (default: 1)
* @param antialiasing Whether antialiasing should be turned on or not (default: false)
* @param fileName A name for for the downloaded file.
* @param renderSprites Whether the sprites should be rendered or not (default: false)
* @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)
* @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)
* @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.
* @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.
*/
export function CreateScreenshotUsingRenderTarget(
engine: Engine,
camera: Camera,
size: IScreenshotSize | number,
successCallback?: (data: string) => void,
mimeType = "image/png",
samples = 1,
antialiasing = false,
fileName?: string,
renderSprites = false,
enableStencilBuffer = false,
useLayerMask = true,
quality?: number,
customizeTexture?: (texture: RenderTargetTexture) => void
): void {
const { height, width, finalWidth, finalHeight } = _GetScreenshotSize(engine, camera, size);
const targetTextureSize = { width, height };
if (!(height && width)) {
Logger.Error("Invalid 'size' parameter !");
return;
}
const originalSize = { width: engine.getRenderWidth(), height: engine.getRenderHeight() };
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
const scene = camera.getScene();
// At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
const texture = new RenderTargetTexture(
"screenShot",
targetTextureSize,
scene,
false,
false,
Constants.TEXTURETYPE_UNSIGNED_INT,
false,
Texture.BILINEAR_SAMPLINGMODE,
undefined,
enableStencilBuffer,
undefined,
undefined,
undefined,
samples
);
texture.renderList = scene.meshes.slice();
texture.samples = samples;
texture.renderSprites = renderSprites;
texture.activeCamera = camera;
texture.forceLayerMaskCheck = useLayerMask;
customizeTexture?.(texture);
const renderWhenReady = () => {
if (texture.isReadyForRendering() && camera.isReady(true)) {
engine.onEndFrameObservable.addOnce(() => {
if (finalWidth === width && finalHeight === height) {
texture.readPixels(undefined, undefined, undefined, false)!.then((data) => {
DumpTools.DumpData(width, height, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true, undefined, quality);
texture.dispose();
});
} else {
ApplyPostProcess("pass", texture.getInternalTexture()!, scene, undefined, undefined, undefined, finalWidth, finalHeight).then((texture) => {
engine._readTexturePixels(texture, finalWidth, finalHeight, -1, 0, null, true, false, 0, 0).then((data) => {
DumpTools.DumpData(
finalWidth,
finalHeight,
data,
successCallback as (data: string | ArrayBuffer) => void,
mimeType,
fileName,
true,
undefined,
quality
);
texture.dispose();
});
});
}
});
texture.render(true);
// re-render the scene after the camera has been reset to the original camera to avoid a flicker that could occur
// 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)
scene.incrementRenderId();
scene.resetCachedMaterial();
engine.setSize(originalSize.width, originalSize.height);
camera.getProjectionMatrix(true); // Force cache refresh;
scene.render();
} else {
setTimeout(renderWhenReady, 16);
}
};
const renderToTexture = () => {
// render the RTT
scene.incrementRenderId();
scene.resetCachedMaterial();
renderWhenReady();
};
if (antialiasing) {
const fxaaPostProcess = new FxaaPostProcess("antialiasing", 1.0, scene.activeCamera);
texture.addPostProcess(fxaaPostProcess);
// Async Shader Compilation can lead to none ready effects in synchronous code
if (!fxaaPostProcess.getEffect().isReady()) {
fxaaPostProcess.getEffect().onCompiled = () => {
renderToTexture();
};
}
// The effect is ready we can render
else {
renderToTexture();
}
} else {
// No need to wait for extra resources to be ready
renderToTexture();
}
}
/**
* Generates an image screenshot from the specified camera.
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
* @param engine The engine to use for rendering
* @param camera The camera to use for rendering
* @param size This parameter can be set to a single number or to an object with the
* following (optional) properties: precision, width, height. If a single number is passed,
* it will be used for both width and height. If an object is passed, the screenshot size
* will be derived from the parameters. The precision property is a multiplier allowing
* rendering at a higher or lower resolution
* @param mimeType The MIME type of the screenshot image (default: image/png).
* Check your browser for supported MIME types
* @param samples Texture samples (default: 1)
* @param antialiasing Whether antialiasing should be turned on or not (default: false)
* @param fileName A name for for the downloaded file.
* @param renderSprites Whether the sprites should be rendered or not (default: false)
* @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)
* @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)
* @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.
* @returns screenshot as a string of base64-encoded characters. This string can be assigned
* to the src parameter of an <img> to display it
*/
export function CreateScreenshotUsingRenderTargetAsync(
engine: Engine,
camera: Camera,
size: IScreenshotSize | number,
mimeType = "image/png",
samples = 1,
antialiasing = false,
fileName?: string,
renderSprites = false,
enableStencilBuffer = false,
useLayerMask = true,
quality?: number
): Promise<string> {
return new Promise((resolve, reject) => {
CreateScreenshotUsingRenderTarget(
engine,
camera,
size,
(data) => {
if (typeof data !== "undefined") {
resolve(data);
} else {
reject(new Error("Data is undefined"));
}
},
mimeType,
samples,
antialiasing,
fileName,
renderSprites,
enableStencilBuffer,
useLayerMask,
quality
);
});
}
/**
* Gets height and width for screenshot size
* @param engine
* @param camera
* @param size
* @private
*/
function _GetScreenshotSize(engine: Engine, camera: Camera, size: IScreenshotSize | number): { height: number; width: number; finalWidth: number; finalHeight: number } {
let height = 0;
let width = 0;
let finalWidth = 0;
let finalHeight = 0;
//If a size value defined as object
if (typeof size === "object") {
const precision = size.precision
? Math.abs(size.precision) // prevent GL_INVALID_VALUE : glViewport: negative width/height
: 1;
//If a width and height values is specified
if (size.width && size.height) {
height = size.height * precision;
width = size.width * precision;
}
//If passing only width, computing height to keep display canvas ratio.
else if (size.width && !size.height) {
width = size.width * precision;
height = Math.round(width / engine.getAspectRatio(camera));
}
//If passing only height, computing width to keep display canvas ratio.
else if (size.height && !size.width) {
height = size.height * precision;
width = Math.round(height * engine.getAspectRatio(camera));
} else {
width = Math.round(engine.getRenderWidth() * precision);
height = Math.round(width / engine.getAspectRatio(camera));
}
//If a finalWidth and finalHeight values is specified
if (size.finalWidth && size.finalHeight) {
finalHeight = size.finalHeight;
finalWidth = size.finalWidth;
}
//If passing only finalWidth, computing finalHeight to keep display canvas ratio.
else if (size.finalWidth && !size.finalHeight) {
finalWidth = size.finalWidth;
finalHeight = Math.round(finalWidth / engine.getAspectRatio(camera));
}
//If passing only finalHeight, computing finalWidth to keep display canvas ratio.
else if (size.finalHeight && !size.finalWidth) {
finalHeight = size.finalHeight;
finalWidth = Math.round(finalHeight * engine.getAspectRatio(camera));
} else {
finalWidth = width;
finalHeight = height;
}
}
//Assuming here that "size" parameter is a number
else if (!isNaN(size)) {
height = size;
width = size;
finalWidth = size;
finalHeight = size;
}
// When creating the image data from the CanvasRenderingContext2D, the width and height is clamped to the size of the _gl context
// 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
// 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
// to resolve this, we truncate the floats here to ensure the same size
if (width) {
width = Math.floor(width);
}
if (height) {
height = Math.floor(height);
}
if (finalWidth) {
finalWidth = Math.floor(finalWidth);
}
if (finalHeight) {
finalHeight = Math.floor(finalHeight);
}
return { height: height | 0, width: width | 0, finalWidth: finalWidth | 0, finalHeight: finalHeight | 0 };
}
/**
* Class containing a set of static utilities functions for screenshots
*/
export const ScreenshotTools = {
/**
* Captures a screenshot of the current rendering
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
* @param engine defines the rendering engine
* @param camera defines the source camera
* @param size This parameter can be set to a single number or to an object with the
* following (optional) properties: precision, width, height. If a single number is passed,
* it will be used for both width and height. If an object is passed, the screenshot size
* will be derived from the parameters. The precision property is a multiplier allowing
* rendering at a higher or lower resolution
* @param successCallback defines the callback receives a single parameter which contains the
* screenshot as a string of base64-encoded characters. This string can be assigned to the
* src parameter of an <img> to display it
* @param mimeType defines the MIME type of the screenshot image (default: image/png).
* Check your browser for supported MIME types
* @param forceDownload force the system to download the image even if a successCallback is provided
* @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.
*/
CreateScreenshot,
/**
* Captures a screenshot of the current rendering
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
* @param engine defines the rendering engine
* @param camera defines the source camera
* @param size This parameter can be set to a single number or to an object with the
* following (optional) properties: precision, width, height. If a single number is passed,
* it will be used for both width and height. If an object is passed, the screenshot size
* will be derived from the parameters. The precision property is a multiplier allowing
* rendering at a higher or lower resolution
* @param mimeType defines the MIME type of the screenshot image (default: image/png).
* Check your browser for supported MIME types
* @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.
* @returns screenshot as a string of base64-encoded characters. This string can be assigned
* to the src parameter of an <img> to display it
*/
CreateScreenshotAsync,
/**
* 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)
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
* @param engine defines the rendering engine
* @param camera defines the source camera
* @param width defines the expected width
* @param height defines the expected height
* @param mimeType defines the MIME type of the screenshot image (default: image/png).
* Check your browser for supported MIME types
* @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.
* @returns screenshot as a string of base64-encoded characters. This string can be assigned
* to the src parameter of an <img> to display it
*/
CreateScreenshotWithResizeAsync,
/**
* Generates an image screenshot from the specified camera.
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
* @param engine The engine to use for rendering
* @param camera The camera to use for rendering
* @param size This parameter can be set to a single number or to an object with the
* following (optional) properties: precision, width, height. If a single number is passed,
* it will be used for both width and height. If an object is passed, the screenshot size
* will be derived from the parameters. The precision property is a multiplier allowing
* rendering at a higher or lower resolution
* @param successCallback The callback receives a single parameter which contains the
* screenshot as a string of base64-encoded characters. This string can be assigned to the
* src parameter of an <img> to display it
* @param mimeType The MIME type of the screenshot image (default: image/png).
* Check your browser for supported MIME types
* @param samples Texture samples (default: 1)
* @param antialiasing Whether antialiasing should be turned on or not (default: false)
* @param fileName A name for for the downloaded file.
* @param renderSprites Whether the sprites should be rendered or not (default: false)
* @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)
* @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.
*/
CreateScreenshotUsingRenderTarget,
/**
* Generates an image screenshot from the specified camera.
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
* @param engine The engine to use for rendering
* @param camera The camera to use for rendering
* @param size This parameter can be set to a single number or to an object with the
* following (optional) properties: precision, width, height. If a single number is passed,
* it will be used for both width and height. If an object is passed, the screenshot size
* will be derived from the parameters. The precision property is a multiplier allowing
* rendering at a higher or lower resolution
* @param mimeType The MIME type of the screenshot image (default: image/png).
* Check your browser for supported MIME types
* @param samples Texture samples (default: 1)
* @param antialiasing Whether antialiasing should be turned on or not (default: false)
* @param fileName A name for for the downloaded file.
* @param renderSprites Whether the sprites should be rendered or not (default: false)
* @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.
* @returns screenshot as a string of base64-encoded characters. This string can be assigned
* to the src parameter of an <img> to display it
*/
CreateScreenshotUsingRenderTargetAsync,
};
/**
* This will be executed automatically for UMD and es5.
* If esm dev wants the side effects to execute they will have to run it manually
* Once we build native modules those need to be exported.
* @internal
*/
const initSideEffects = () => {
// References the dependencies.
Tools.CreateScreenshot = CreateScreenshot;
Tools.CreateScreenshotAsync = CreateScreenshotAsync;
Tools.CreateScreenshotUsingRenderTarget = CreateScreenshotUsingRenderTarget;
Tools.CreateScreenshotUsingRenderTargetAsync = CreateScreenshotUsingRenderTargetAsync;
};
initSideEffects();