Canvas灰度图

var context = canvas.get(0).getContext("2d");
var offlineImg = context.getImageData(0,0,40,40);
var pix = offlineImg.data;
for (var i = 0, n = pix.length; i < n; i += 4) {
	var grayscale = pix[i] * .3 + pix[i+1] * .59 + pix[i+2] * .11;
	pix[i] = pix[i+1] = pix[i+2] = grayscale;
}
context.putImageData(offlineImg,0,0);

 

发表评论

您的电子邮箱地址不会被公开。