phaser/src/renderer/snapshot/CanvasSnapshot.js

34 lines
1 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2018-02-12 16:01:20 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2018-02-09 13:46:04 +00:00
/**
2018-10-22 11:12:31 +00:00
* Takes a snapshot of the current frame displayed by a 2D canvas.
2018-02-09 13:46:04 +00:00
*
* @function Phaser.Renderer.Snapshot.Canvas
* @since 3.0.0
*
2018-10-22 11:12:31 +00:00
* @param {HTMLCanvasElement} canvas - The canvas to take a snapshot of.
* @param {string} [type='image/png'] - The format of the returned image.
* @param {number} [encoderOptions=0.92] - The image quality, between 0 and 1, for image formats which use lossy compression (such as `image/jpeg`).
2018-02-09 13:46:04 +00:00
*
2018-10-19 11:32:43 +00:00
* @return {HTMLImageElement} Returns an image of the type specified.
2018-02-09 13:46:04 +00:00
*/
var CanvasSnapshot = function (canvas, type, encoderOptions)
2017-05-16 19:15:01 +00:00
{
if (type === undefined) { type = 'image/png'; }
if (encoderOptions === undefined) { encoderOptions = 0.92; }
var src = canvas.toDataURL(type, encoderOptions);
var image = new Image();
2017-05-16 19:15:01 +00:00
image.src = src;
2017-05-16 19:15:01 +00:00
return image;
};
module.exports = CanvasSnapshot;