微信小程序API 繪圖·導(dǎo)出圖片canvasToTempFilePath(OBJECT)

2022-05-09 16:34 更新

微信小程序 canvas接口和方法繪圖接口和方法

wx.canvasToTempFilePath(OBJECT)


把當(dāng)前畫布指定區(qū)域的內(nèi)容導(dǎo)出生成指定大小的圖片,并返回文件路徑。

OBJECT參數(shù)說(shuō)明:

參數(shù) 類型 必填 說(shuō)明 最低版本
x Number 畫布x軸起點(diǎn)(默認(rèn)0) 1.2.0
y Number 畫布y軸起點(diǎn)(默認(rèn)0) 1.2.0
width Number 畫布寬度(默認(rèn)為canvas寬度-x) 1.2.0
height Number 畫布高度(默認(rèn)為canvas高度-y) 1.2.0
destWidth Number 輸出圖片寬度(默認(rèn)為width) 1.2.0
destHeight Number 輸出圖片高度(默認(rèn)為height) 1.2.0
canvasId String 畫布標(biāo)識(shí),傳入 <canvas/> 的 cavas-id
fileType String 目標(biāo)文件的類型,只支持 'jpg' 或 'png'。默認(rèn)為 'png' 1.7.0
quality Number 圖片的質(zhì)量,取值范圍為 (0, 1],不在范圍內(nèi)時(shí)當(dāng)作1.0處理 1.7.0
success Function 接口調(diào)用成功的回調(diào)函數(shù)
fail Function 接口調(diào)用失敗的回調(diào)函數(shù)
complete Function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行)


示例代碼

wx.canvasToTempFilePath({
  x: 100,
  y: 200,
  width: 50,
  height: 50,
  destWidth: 100,
  destHeight: 100,
  canvasId: 'myCanvas',
  success: function(res) {
    console.log(res.tempFilePath)
  } 
})

微信小程序 canvas接口和方法繪圖接口和方法

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)