src/video/canvas/canvas_renderer.js
function (image, sx, sy, sw, sh, dx, dy, dw, dh) {
            if (this.backBufferContext2D.globalAlpha < 1 / 255) {
                // Fast path: don't draw fully transparent
                return;
            }

            if (typeof sw === "undefined") {
                sw = dw = image.width;
                sh = dh = image.height;
                dx = sx;
                dy = sy;
                sx = 0;
                sy = 0;
            }
            else if (typeof dx === "undefined") {
                dx = sx;
                dy = sy;
                dw = sw;
                dh = sh;
                sw = image.width;
                sh = image.height;
                sx = 0;
                sy = 0;
            }

            if (this.settings.subPixel === false) {
                // clamp to pixel grid
                dx = ~~dx;
                dy = ~~dy;
            }

            this.backBufferContext2D.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh);
        }
function (image, sx, sy, sw, sh, dx, dy, dw, dh) {
            if (this.backBufferContext2D.globalAlpha < 1 / 255) {
                // Fast path: don't draw fully transparent
                return;
            }

            if (typeof sw === "undefined") {
                sw = dw = image.width;
                sh = dh = image.height;
                dx = sx;
                dy = sy;
                sx = 0;
                sy = 0;
            }
            else if (typeof dx === "undefined") {
                dx = sx;
                dy = sy;
                dw = sw;
                dh = sh;
                sw = image.width;
                sh = image.height;
                sx = 0;
                sy = 0;
            }

            if (this.settings.subPixel === false) {
                // clamp to pixel grid
                dx = ~~dx;
                dy = ~~dy;
            }

            this.backBufferContext2D.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh);
        }
function ( image , sx , sy , sw , sh , dx , dy , dw , dh ) { if ( this . backBufferContext2D . globalAlpha < 1 / 255 ) { // Fast path: don't draw fully transparent return ; } if ( typeof sw === "undefined" ) { sw = dw = image . width ; sh = dh = image . height ; dx = sx ; dy = sy ; sx = 0 ; sy = 0 ; } else if ( typeof dx === "undefined" ) { dx = sx ; dy = sy ; dw = sw ; dh = sh ; sw = image . width ; sh = image . height ; sx = 0 ; sy = 0 ; } if ( this . settings . subPixel === false ) { // clamp to pixel grid dx = ~ ~ dx ; dy = ~ ~ dy ; } this . backBufferContext2D . drawImage ( image , sx , sy , sw , sh , dx , dy , dw , dh ) ; }
Draw an image onto the main using the canvas api
@name drawImage
@memberOf me.CanvasRenderer.prototype
@function
@param {Image} image An element to draw into the context. The specification permits any canvas image source (CanvasImageSource), specifically, a CSSImageValue, an HTMLImageElement, an SVGImageElement, an HTMLVideoElement, an HTMLCanvasElement, an ImageBitmap, or an OffscreenCanvas.
@param {Number} sx The X coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
@param {Number} sy The Y coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
@param {Number} sw The width of the sub-rectangle of the source image to draw into the destination context. If not specified, the entire rectangle from the coordinates specified by sx and sy to the bottom-right corner of the image is used.
@param {Number} sh The height of the sub-rectangle of the source image to draw into the destination context.
@param {Number} dx The X coordinate in the destination canvas at which to place the top-left corner of the source image.
@param {Number} dy The Y coordinate in the destination canvas at which to place the top-left corner of the source image.
@param {Number} dWidth The width to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in width when drawn.
@param {Number} dHeight The height to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in height when drawn.
@example
// Position the image on the canvas:
renderer.drawImage(image, dx, dy);
// Position the image on the canvas, and specify width and height of the image:
renderer.drawImage(image, dx, dy, dWidth, dHeight);
// Clip the image and position the clipped part on the canvas:
renderer.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
Draw an image onto the main using the canvas api