Skip to content

Canvas.toTempFilePathSync ​

JS
    string Canvas.toTempFilePathSync(Object object)

Saves the current canvas content as a temporary file.

This is the synchronous version of Canvas.toTempFilePath. The webgl context can only be operated within the render loop (the 2d context is not subject to this restriction). Calling this API inside the requestAnimationFrame callback function ensures it runs within the render loop.

Parameters

  • Object object: Input parameters. See the table below for details.

object properties:

PropertyTypeRequiredDefaultDescription
xnumberNo0X coordinate of the top-left corner of the canvas region to capture
ynumberNo0Y coordinate of the top-left corner of the canvas region to capture
widthnumberNocanvas widthWidth of the canvas region to capture
heightnumberNocanvas heightHeight of the canvas region to capture
destWidthnumberNocanvas widthWidth of the output file; the captured region will be stretched or compressed to this value; only effective when fileType is jpg
destHeightnumberNocanvas heightHeight of the output file; the captured region will be stretched or compressed to this value; only effective when fileType is jpg
fileTypestringNopngType of the output file; only png and jpg are supported
qualitynumberNo1.0Quality of the jpg image; only effective when fileType is jpg. Valid range is 0.0 (lowest) - 1.0 (highest), excluding 0. Values out of range are treated as 1.0

Return Value

  • string: Temporary file path generated by canvas (local path)