简体   繁体   English

如何使用camanjs更改图像不透明度?

[英]How to change image opacity with camanjs?

how to change image opacity with caman js I tried with lates version also. 我也尝试过使用最新版本的caman js更改图像不透明度。 Still issue is coming. 仍然有问题。 If anything need to enable to achieve this ? 是否需要实现这一目标? //throwing not defined with caman js. //未使用caman js定义的投掷。 In this reference - https://www.sitepoint.com/manipulating-images-web-pages-camanjs/ this.opacity(20); 在本参考中-https : //www.sitepoint.com/manipulating-images-web-pages-camanjs/ this.opacity(20);

Add these filter in camen.js 在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. 现在,不透明度过滤器将起作用。

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

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