# string Canvas.toTempFilePath(Object object)

Saves the current canvas as a temporary file.

# Parameters

# Object object

Attribute Type Default Required Description
x number 0 No The x-coordinate of the top-left corner of the truncated canvas
y number 0 No The y-coordinate of the top-left corner of the truncated canvas
width number The canvas width No The width of the truncated canvas
height number The canvas height No The height of the truncated canvas
destWidth number The canvas width No The width of the destination file. The truncated part will be stretched or compressed to this value.
destHeight number The canvas height No The height of the destination file. The truncated part will be stretched or compressed to this value.
fileType string png No The type of the destination file
quality number 1.0 No The quality of jpg images, which is valid only when fileType is jpg. Value range: 0.0 (lowest) to 1.0 (highest), exclusive of 0. 1.0 is used when the specified value falls outside this range.
success function No The callback function for a successful API call
fail function No Callback function for failed API call
complete function No Callback function used when API call completed (always executed whether call succeeds or fails)

Valid values of object.fileType

Value Description Minimum Version
jpg jpg file
png png file

# Return Values

# string

The temporary file path generated for canvas.

# Sample Code

Canvas.toTempFilePath


canvas.toTempFilePath({
  x: 10,
  y: 10,
  width: 200,
  height: 150,
  destWidth: 400,
  destHeight: 300,
  success: (res) => {
    wx.shareAppMessage({
      imageUrl: res.tempFilePath
    })
  }
})

Canvas.toTempFilePathSync


let tempFilePath = canvas.toTempFilePathSync({
  x: 10,
  y: 10,
  width: 200,
  height: 150,
  destWidth: 400,
  destHeight: 300
})
wx.shareAppMessage({
  imageUrl: tempFilePath
})