简体   繁体   English

如何在dynamicjs中删除图像过滤器?

[英]How to remove filter for image in kineticjs?

I can add filter to image like here : 我可以像这样图像上添加过滤器:

// apply grayscale filter to second image
filteredYoda.applyFilter({
    filter: Kinetic.Filters.Grayscale,
    callback: function() {
        layer.draw();
    }
});

, but how I can remove it and get initial image? ,但是如何删除它并获得初始图像?

UPDATE: the code that solves the problem: 更新:解决问题的代码:

    imageCanvas.initailImage = imageCanvas.getImage();
    imageCanvas.disconnect = function () {
        imageCanvas.applyFilter({
            filter: Kinetic.Filters.Grayscale,
            callback: function() {
                //imageCanvas.deviceName += " - Disconnected.";
                stage.get('#deviceLayer')[0].draw();
            }
        });
    };
    imageCanvas.connect = function () {
        if (imageCanvas.hasOwnProperty('initailImage')) {
            imageCanvas.setImage(imageCanvas.initailImage);
            stage.get('#deviceLayer')[0].draw();
        }
    };

There doesn't seem to be any way of doing this at moment. 目前似乎没有任何方法可以这样做。 I've poked around in the source code of the current version, and I can't find any function call that would remove a filter. 我在当前版本的源代码中四处摸索,但找不到任何可以删除过滤器的函数调用。

The filters themselves are actually functions that apply a little bit of maths to the raw image data, so one approach might be to define your own filter which applies the inverse equation. 过滤器本身实际上是对原始图像数据进行一点数学运算的函数,因此一种方法可能是定义自己的应用反方程的过滤器。 However, it might prove to be impossible to compute the original values without adding extra complexity. 但是,在不增加额外复杂性的情况下,可能无法计算原始值。

So, if you don't want try that (and who would blame you..), you could also just make a new Image from the same source and store it separately, to be shown as the filtered image. 因此,如果您不想尝试该操作(以及谁会责怪您..),您也可以仅从同一来源制作一个新图像并将其单独存储,以显示为过滤后的图像。 It's a little tiresome, and unfortunately the clone method doesn't work properly right now either (you'll get a reference to the same variable), but it might be the simplest approach. 这有点累,而且不幸的是,clone方法现在也无法正常工作(您将获得对相同变量的引用),但这可能是最简单的方法。

And finally, of course, you might prefer to wait for more filter support to be implemented. 最后,当然,您可能更希望等待更多过滤器支持被实施。 I couldn't tell you when this might happen, though. 不过,我无法告诉您什么时候会发生。

Easy use the following 易于使用以下

YOURIMAGEORSHAPE.clearFilter(); 
stage.draw(); // or layer.draw(); depending on your setup 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM