简体   繁体   中英

CamanJS - replace instance

If I have an image that I apply a filter to, eg Lomo filter, is there way to make that the current Caman instance?

Meaning, if I then want to then play about with the brightness on the image that I applied the filter to, and use this.revert(); to reset the brightness, I want it to revert to the canvas with the filter on it that I just applied.

Is this possible?

I'm having a nightmare with trying to apply many effects, only one at once (except for preset filters), and carry the state through...

If i understand, you want to apply filter ("Lomo") as shown on their example page and then fiddle with some properties (like brightness) and then revert changes back to "Lomo" filter?

Why not just click on filter ("Lomo") again?

EDIT: You should probably take a look at guide and implement your own method with default values like in filters.

u.Filter.register("lomo", function (D) {
        if (D == null) {
            D = true
        }
        this.brightness(15);
        this.exposure(15);
        this.curves("rgb", [0, 0], [200, 0], [155, 255], [255, 255]);
        this.saturation(-20);
        this.gamma(1.8);
        if (D) {
            this.vignette("50%", 60)
        }
        return this.brightness(5)
    });

I dont think your requirement comes "out of the box".

If i understand you correctly , You want to apply a filter and play with other effects like brightness and contrast etc.,
I made some code which will work according to your need

 Caman('#canvas-camanImage',"./../media/caman.png", function () {
        this.revert(false);
        for(var i = 0 ;i<selectedPresets.length;i++){
            this[selectedPresets[i]]();
        }
        for(var key in effect){
            this[key](effect[key].value);
        }
        this.render(function () {
        });

in the above code i am storing all effects like brightness contrast in effect variable like effect = { brightness : { min : -100, max: 100, value : 0 }, contrast : { min : -100, max: 100, value : 0 }, saturation : { min : -100, max: 100, value : 0 } };

and presets in an array

presets = [
    {filter:'vintage',name : 'Vintage'},
    {filter:'lomo',name:'Lomo'},
    {filter: 'clarity', name:'Clarity'},
    {filter:'sinCity', name:'Sin City'}
    ];

So every time you add any preset or change any effect value i am changing the values in variable and rendering canvas again
It is working very fine for me
Let me know if your concern is something else

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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