English 中文(简体)
使用javascript的画布图像的亮度和对比度
原标题:Brightness and Contrast for a canvas image with javascript

我在标签中有一个图像

var img = new Image();
ctx.drawImage(img,0,0,img.width,img.height);
ecc...

如何使用javascript更改此图像的亮度和对比度?

Tnx公司

最佳回答

据我所知,至少有一个javascript库可以做到这一点,像素

用法可能是这样的。

Pixastic.process(canvas,  brightness ,
    {
         brightness : 60,
         contrast : 0.5,
         leaveDOM : true
    },
    function(img) {
        ctx.drawImage(img, 0, 0);
    }
);

该库在某种程度上是用来处理页面中的图像的,它将它们替换为包含渲染结果的画布元素。

但在上面的代码中,我传入了一个画布元素而不是图像,并包含了leaveDOM属性,以防止pixastic库将您在DOM中的画布替换为它创建的画布。

为了显示结果,我包含了回调函数,该函数只执行ctx.drawImage将内容放入原始画布中。

希望这是有道理的。

您可以查看文档以了解更多示例像素文档

问题回答

根据我的经验,fabric.js是执行此操作的最佳javascript库。查看Fabric JS以及如何进行图像过滤,网址:http://fabricjs.com/image-filters

你可以试试看评论

<script type="application/javascript">  

function clickMeEvent(obj)
{
if (obj.style.opacity=="0.9")
    {
    obj.style.opacity="0.7";
    }
else if (obj.style.opacity=="0.7")
    {
    obj.style.opacity="0.5";        
    }
else if (obj.style.opacity=="0.5")
    {
    obj.style.opacity="0.3";        
    }
else if (obj.style.opacity=="0.3")
    {
    obj.style.opacity="0.1";        
    }
else
    {
    obj.style.opacity="0.0";

    }
}

</script>





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签