【发布时间】:2021-09-13 13:12:44
【问题描述】:
我有几个滑块,每个滑块对我的画布应用不同的过滤器(见下图)。
但是当我多次使用相同的滑块时,相同的过滤器会叠加在画布上。 (参见下图中的filters 属性)。
我希望过滤器仅在它们来自相同的滑块输入时才能相互替换。即Brightness 和Saturation 可以同时存在,但永远不会有2 个Brightness 堆叠在一起。我还发现我不能依赖filters 中的type 属性,因为我的一些滑块可能会导致相同的type。这个问题有什么顺利的解决办法吗?
以下是当前如何将过滤器应用于画布的示例代码。
function saturate(o, value){
value = value / 100
let filter = new fabric.Image.filters.Saturation({
saturation: value,
});
if (o.filters) {
o.filters = []
o.filters.push(filter);
o.applyFilters();
}
}
**Below is the output of `canvas.toObject()` (see the `filter` attribute)**
【问题讨论】:
标签: javascript reactjs canvas fabricjs