「基础库2.16.1」offscreenContext2d getImageData返回全0数组?
发布于 6 年前 作者 xiuying12 14789 次浏览 来自 问答

基础库: 2.16.1

真机预览设备:安卓Huawei Mate 20,苹果iphone12pro

代码:

const offscreenCanvas = wx.createOffscreenCanvas({ type: '2d'});
const offscreenContext = offscreenCanvas.getContext('2d');
offscreenContext.drawImage(image, 0, 0, width, height);
const imageData = offscreenContext.getImageData(0, 0, width, height);
console.log(imageData.data);

在真机输出结果是一个width*height*4 的全0数组,但是在开发者工具可以输出正确的非0数据

对于获取imageData的问题之前已提过一次:https://developers.weixin.qq.com/community/develop/doc/0008aeea438a78027cfb5fd9b52000

手机开启调试得到WeChatLib为2.16.1(2021.4.21 17:27:25),确定手机运行的是2.16.1基础库

是写法问题还是小程序还不支持?

1 回复

你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

回到顶部