W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
解釋:返回一個(gè)數(shù)組,用來(lái)描述 canvas 區(qū)域隱含的像素?cái)?shù)據(jù)。在自定義組件下,操作組件內(nèi) <canvas> 組件。
Object object
屬性名 | 類型 | 必填 | 默認(rèn)值 | 說(shuō)明 |
---|---|---|---|---|
canvasId | String | 是 | 畫布標(biāo)識(shí),傳入 | |
x | Number | 是 | 將要被提取的圖像數(shù)據(jù)矩形區(qū)域的左上角橫坐標(biāo) | |
y | Number | 是 | 將要被提取的圖像數(shù)據(jù)矩形區(qū)域的左上角縱坐標(biāo) | |
width | Number | 是 | 將要被提取的圖像數(shù)據(jù)矩形區(qū)域的寬度 | |
height | Number | 是 | 將要被提取的圖像數(shù)據(jù)矩形區(qū)域的高度 | |
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í)行) |
參數(shù) | 類型 | 說(shuō)明 |
---|---|---|
width | Number | 圖像數(shù)據(jù)矩形的寬度 |
height | Number | 圖像數(shù)據(jù)矩形的高度 |
data | Uint8ClampedArray | 圖像像素點(diǎn)數(shù)據(jù),一維數(shù)組,每四項(xiàng)表示一個(gè)像素點(diǎn)的 rgba 。 |
<canvas canvas-id="myCanvas" class="canvas" />
<button type="primary" bindtap="canvasGetImageData">canvasGetImageData</button>
Page({
onReady: function () {
const CanvasContext = this.createCanvasContext('myCanvas');
CanvasContext.setFillStyle('#0f0f0f');
CanvasContext.arc(100, 100, 50, 0, 2 * Math.PI);
CanvasContext.fill();
CanvasContext.beginPath();
CanvasContext.setStrokeStyle('#0000ff');
CanvasContext.moveTo(90, 70);
CanvasContext.lineTo(70, 80);
CanvasContext.lineTo(90, 80);
CanvasContext.closePath();
CanvasContext.stroke();
CanvasContext.beginPath();
CanvasContext.setStrokeStyle('#0000ff');
CanvasContext.moveTo(130, 70);
CanvasContext.lineTo(110, 80);
CanvasContext.lineTo(130, 80);
CanvasContext.closePath();
CanvasContext.stroke();
CanvasContext.beginPath();
CanvasContext.setFillStyle('#00ff00');
CanvasContext.arc(100, 100, 20, 0, 1 * Math.PI);
CanvasContext.fill();
CanvasContext.setFillStyle('#00ff00');
CanvasContext.setFontSize(12);
CanvasContext.fillText('hello', 165, 78);
CanvasContext.moveTo(100, 50);
CanvasContext.setStrokeStyle('#00ff00');
CanvasContext.bezierCurveTo(100, 25, 75, 25, 50, 50);
CanvasContext.stroke();
CanvasContext.moveTo(100, 50);
CanvasContext.quadraticCurveTo(75, 25, 50, 50);
CanvasContext.stroke();
CanvasContext.draw();
},
canvasGetImageData() {
swan.canvasGetImageData({
canvasId: 'myCanvas',
x: 0,
y: 0,
width: 100,
height: 100,
success: res => {
console.log('canvasGetImageData success', res);
swan.showModal({
title: '返回結(jié)果',
content: JSON.stringify(res)
});
},
fail: err => {
console.log('canvasGetImageData fail', err);
}
});
}
});
錯(cuò)誤碼 | 說(shuō)明 |
---|---|
201 | 解析失敗,請(qǐng)檢查調(diào)起協(xié)議是否合法。 |
錯(cuò)誤碼 | 說(shuō)明 |
---|---|
202 | 解析失敗,請(qǐng)檢查參數(shù)是否正確。 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: