How to get a pixel's x,y coordinate color from an image?

后端 未结 4 1904
时光说笑
时光说笑 2020-11-22 09:00

Is there any way to check if a selected(x,y) point of a PNG image is transparent?

4条回答
  •  醉话见心
    2020-11-22 09:40

    With : i << 2

    const data = context.getImageData(x, y, width, height).data;
    const pixels = [];
    
    for (let i = 0, dx = 0; dx < data.length; i++, dx = i << 2) {
        if (data[dx+3] <= 8)
            console.log("transparent x= " + i);
    }
    

提交回复
热议问题