我在浏览器上有一张图片。
我想获取图像颜色的左上角像素(坐标:0,0),无论图像是否旋转。
我该如何使用 javascript 或 php 代码来做到这一点?
- 创建画布文档.createElement
- 获取二维上下文
canvas.getContext('2d')
- Draw the image to the canvas
context.drawImage(image, x, y)
- Get the pixel data for the image
context.getImageData(x1, y1, x2, y2)
- 你只想要左上角所以
context.getImageData(0, 0, 1, 1)
- The result of getImageData will have an array of pixels in it's
data
field (context.getImageData(0,0,1,1).data
)
- 该数组将有
r
, g
, b
and a
values.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)