【问题标题】:a color change in transparency透明度的颜色变化
【发布时间】:2012-05-16 21:59:30
【问题描述】:

我在 javascript HTML5 画布中生成了一张图片。 我现在想说的是,某种颜色(比如红色)的所有px都变成了透明的

【问题讨论】:

标签: html html5-canvas


【解决方案1】:
var imgd = context.getImageData(0,0, canvas.widht, canvas.height);
var pix = imgd.data;

// Loop over each pixel and set alpha channel to 255 for every red pixel
for (var i = 0; n = pix.length, i < n; i += 4) {
  if ( pix[i  ] > 240 && pix[i+1 ] < 15 && pix[i+2] < 15 ) // it is kind of red
      pix[i+3] = 255; // alpha channel
}

// Draw the ImageData object at the given (x,y) coordinates.
context.putImageData(imgd, 0,0);

我没有测试代码,但它应该可以工作(如果没有,你有全局想法)

【讨论】:

  • peeeeeeeeeeeeeeeeeeeeeeeeeeeeeerfect!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-19
  • 1970-01-01
  • 2012-07-03
  • 2021-07-26
  • 2012-07-11
  • 2011-10-06
  • 2016-04-24
相关资源
最近更新 更多