简体   繁体   中英

How to change image opacity with camanjs?

how to change image opacity with caman js I tried with lates version also. Still issue is coming. If anything need to enable to achieve this ? //throwing not defined with caman js. In this reference - https://www.sitepoint.com/manipulating-images-web-pages-camanjs/ this.opacity(20);

Add these filter in camen.js

Filter.register("opacity", function (adjust) {
        adjust = Math.floor(255 * (adjust / 100)); 
        var imageData = this.imageData.data,
            length = imageData.length;
        // set every fourth value to 50
        for (var i = 3; i < length; i += 4) {
            imageData[i] = imageData[i] == 0 ? imageData[i] : adjust;
        }
        // after the manipulation, reset the data
        this.imageData.data = imageData;
        this.context.putImageData(this.imageData, 0, 0); 
    });

Now opacity filter will work.

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