ImageData是图片的数据化,具备以下属性:
data:Unit8ClampedArray [r,g,b,a,r,g,b,a,r,g,b,a,r,g,b,a]
width:整数
heigth:整数
Unit8ClampedArray翻译为:8位无符号整型固定数组,其取值范围是[0,255]。r若小于0,则为0,大于255,则为255。若为小数,则取整,取整的方法是银行家舍入。
1.直接建立ImageData()对象,相当于自己建立了一张图片;
new ImageData()
new ImageData(width,height)
new ImageData(data:Unit8ClampedArray ,width,height)

ctx.createImageData() 上下文建立ImageData对象
ctx.createImageData(width,height)
ctx.createImageData(ImageData)

2.获取canvas的ImageData()对象,(可以以此原理获取真实图片的数据)
ctx.getImageData(x,y,width,height)
3.putImageData(imgDt,dx,dy,x,y,w,h)

网友评论