9***@qq.com
9***@qq.com
  • 发布:2025-01-08 15:06
  • 更新:2025-01-08 15:06
  • 阅读:57

大佬们,我获取不到像素点信息,需要怎么做?uniapp x中

分类:uni-app x

返回数据:
//‍[⁠io.dcloud.canvas.ImageDataImpl⁠]‍
{
"data":
//‍[⁠io.dcloud.uts.Uint8ClampedArray⁠]‍
{},
"height":
//‍[Int]‍
1,
"width":
//‍[Int]‍
1
}

运行代码:
onReady(() => {
uni.createCanvasContextAsync({
id: 'canvas',
component: getCurrentInstance()?.proxy,
success: (context : CanvasContext) => {
const canvasContext = context.getContext('2d')!;
const canvas = canvasContext.canvas;

            // 处理高清屏逻辑  
            const dpr = uni.getDeviceInfo().devicePixelRatio ?? 1;  
            canvas.width = canvas.offsetWidth * dpr;  
            canvas.height = canvas.offsetHeight * dpr;  
            canvasContext.scale(dpr, dpr); // 仅需调用一次,当调用 reset 方法后需要再次 scale  

            const image = context.createImage();  
            image.src = "../../static/img-color-disk.png";  
            image.onload = () => {  
                console.log('image onLoad');  
                canvasContext.drawImage(image, 0, 0, canvas.offsetWidth, canvas.offsetHeight);  

                setTimeout(() => {  
                    console.log(canvasContext.getImageData(20, 20, 1, 1))  
                }, 3000)  
            }  
        }  
    })  
})
2025-01-08 15:06 负责人:无 分享
已邀请:

要回复问题请先登录注册