【发布时间】:2018-03-18 17:46:08
【问题描述】:
我一直在使用 GLFX.js,并且能够设置一些效果。然而,我缺少的是能够以一种分层/混合的方式一起使用每种效果。目前,如果我增加说棕褐色的滑块,然后增加饱和度的值,棕褐色将重置。我倾向于每次更新滑块时都需要以某种方式保存图像上效果的当前值,但不知道如何去做。任何帮助将不胜感激。先感谢您!这是我的 Javascript 代码:
`
window.onload = function() {
// try to create a WebGL canvas (will fail if WebGL isn't supported)
try {
var canvas = fx.canvas();
} catch (e) {
alert(e);
return;
}
// convert the image to a texture
var image = document.getElementById("image");
var texture = canvas.texture(image);
let sepiaSlider, sepiaFilter, hueSatFltr, hueSldr, satSldr;
canvas.draw(texture).update();
sepiaSlider = document.getElementById("sepia-slider");
hueSldr = document.getElementById("hue-slider");
satSldr = document.getElementById("sat-slider");
hueSldr.addEventListener("input", function(hueVal) {
hueVal = this.value;
console.log(hueVal);
canvas.draw(texture).hueSaturation(hueVal, 0).update();
});
satSldr.addEventListener("input", function(satVal) {
satVal = this.value;
canvas
.draw(texture)
.hueSaturation(0, satVal)
.update();
});
sepiaSlider.addEventListener("input", function(sepiaValue) {
sepiaValue = this.value;
console.log(sepiaValue);
canvas
.draw(texture)
.sepia(sepiaValue)
.update();
});
// replace the image with the canvas
image.parentNode.insertBefore(canvas, image);
image.parentNode.removeChild(image);
};
`
【问题讨论】:
标签: javascript image-processing frameworks