使用 JavaScript 调整画布图像的亮度和对比度
我的标签中有一个图像
var img = new Image();
ctx.drawImage(img,0,0,img.width,img.height);
ecc...
如何使用 javascript 更改该图像的亮度和对比度?
总氮
I have an image in a tag
var img = new Image();
ctx.drawImage(img,0,0,img.width,img.height);
ecc...
How is possible to change the Brightness and Contrast of this image with javascript?
Tnx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我知道至少有一个 javascript 库可以做到这一点, Pixastic
用法可能看起来像这。
该库旨在处理页面中的图像,并将它们替换为包含渲染结果的画布元素。
但在上面的代码中,我传入了一个 canvas 元素而不是图像,并包含了“leaveDOM”属性,以防止 pixastic 库将 DOM 中的画布替换为其创建的画布。
为了显示结果,我添加了回调函数,该函数仅执行 ctx.drawImage 将内容放入原始画布中。
希望这是有道理的。
您可以查看文档以获取更多示例。 Pixastic 文档
There's at least one javascript library I know of which can do this, Pixastic
Usage might look like this.
The library is kind of intended to work with images within your page and it replaces them with canvas elements which contain the rendered result.
But in the code above I've passed in a canvas element rather than an image and included the 'leaveDOM' property to prevent the pixastic library from swapping your canvas in the DOM for the one it creates.
To display the results I've included the callback function which just does ctx.drawImage to put the contents into your original canvas.
Hope that makes sense.
You can check the documentation for more examples. Pixastic Documentation
根据我的经验,fabric.js 是执行此操作的最佳 JavaScript 库。查看 Fabric JS 以及如何进行图像过滤:http://fabricjs.com/image-filters
In my experience, fabric.js is the best javascript library for performing this. Check out Fabric JS and how to do image filtering at: http://fabricjs.com/image-filters
你可以试试这个(c#代码):
You can try this (c# code):
你可以试试这个,看评论
you can try this , see comment