gpt4 book ai didi

javascript - 如何使用createjs为图像应用渐变颜色?

转载 作者:行者123 更新时间:2023-12-03 00:27:51 28 4
gpt4 key购买 nike

如何使用createjs应用渐变填充?下面是用于创建加载图像的代码,我已经使用滤色器更改了颜色,但我想应用渐变颜色

 let rightContainer = new createjs.Container();
let rightMain = new window.createjs.Bitmap(rightImage);
// leftMain.scaleX = 800 / leftMain.image.width;
rightMain.scaleY = 800 / rightMain.image.height;
rightContainer.addChild(rightMain);
rightMain.x = 300;
rightMain.y = 0;
this.layerImage = rightMain.clone();
this.layerImage.alpha = 0.15;
rightContainer.addChild(this.layerImage);
rightMain.filters = [new window.createjs.ColorFilter(0, 0, 0, 1, 117, 111, 115, 0)];
rightContainer.main = rightMain;
rightMain.cache(0, 0, rightMain.image.width, rightMain.image.height);
rightContainer.visible = false;
this.stage.addChild(rightContainer);

最佳答案

你到底想做什么?在滤色图像上应用渐变?

您可以使用的方法是:

  1. 绘制一个带有渐变的方框
  2. 对其进行缓存,以便可以将其用作 AlphaMaskFilter
  3. 将其作为过滤器应用于位图
  4. 缓存位图以应用过滤器。

我做了一个演示来展示它是如何工作的: https://jsfiddle.net/lannymcnie/uog3hkpd/2/

// Draw a gradient in a shape:
s.graphics.lf(["#000", "rgba(0,0,0,0)"], [0, 0], 0,0,960,0);

// Cache the shape
s.cache(0,0,960,400);

// Add the alphamaskfilter + a color adjustment for fun
var col = new createjs.ColorMatrix().adjustHue(180);
bmp.filters = [
new createjs.AlphaMaskFilter(s.cacheCanvas),
new createjs.ColorMatrixFilter(col)
];

// Cache it to apply filters
bmp.cache(0,0,960,400);

该演示还做了一些其他事情,例如

  • 在下面添加第二个未过滤的 bmp
  • 动画渐变比例(需要重新缓存)

希望对您的问题有所帮助。如果您有任何需要帮助的特定代码或示例,请随时澄清。

干杯,

关于javascript - 如何使用createjs为图像应用渐变颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53996758/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com