wx.canvasPutImageData
怎么样实时显示图片,图片是websocket发送过来的数据,显示出来是花屏,有人知道吗?
wx.onSocketMessage(function(res) {
wx.canvasGetImageData({
canvasId: 'video',
x: 0,
y: 0,
width: 200,
height: 200,
success(rs) {
# res.data 是webscoket 传过来的 ArrayBuffer
let pixels = rs.data;
var buffer = new Uint8Array(res.data);
for (var i = 0; i < pixels.length; i++) {
pixels[i] = buffer[i];
}
wx.canvasPutImageData({
canvasId: 'video',
data: pixels,
x: 0,
y: 0,
width: 200,
height: 200
})
},
fail(res) {
console.log(res)
}
})
})
返原图片截图,用<image>可以返原图片显示。