微信小程序API繪圖導(dǎo)出圖片,把畫(huà)布指定區(qū)域的內(nèi)容導(dǎo)出圖片
2020-09-27
導(dǎo)讀:繪圖接口和方法 wx.canvasToTempFilePath(OBJECT) 把當(dāng)前畫(huà)布指定區(qū)域的內(nèi)容導(dǎo)出生成指定大小的圖片,并返回文件路徑。 OBJECT參數(shù)說(shuō)明: 參數(shù) 類型 必填 說(shuō)明 最低版本 x Number 否 畫(huà)布x軸起點(diǎn)...
wx.canvasToTempFilePath(OBJECT)
把當(dāng)前畫(huà)布指定區(qū)域的內(nèi)容導(dǎo)出生成指定大小的圖片,并返回文件路徑。
OBJECT參數(shù)說(shuō)明:
參數(shù) | 類型 | 必填 | 說(shuō)明 | 最低版本 |
---|---|---|---|---|
x | Number | 否 | 畫(huà)布x軸起點(diǎn)(默認(rèn)0) | 1.2.0 |
y | Number | 否 | 畫(huà)布y軸起點(diǎn)(默認(rèn)0) | 1.2.0 |
width | Number | 否 | 畫(huà)布寬度(默認(rèn)為canvas寬度-x) | 1.2.0 |
height | Number | 否 | 畫(huà)布高度(默認(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 | 是 |
畫(huà)布標(biāo)識(shí),傳入<canvas/> 的 cavas-id |
|
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)
}
})
更多微信小程序開(kāi)發(fā)教程,可以關(guān)注hi小程序。
第二部分:如何開(kāi)通一個(gè)小商店