颜色到黑白 javascript 的影响

发布于 2024-08-17 03:49:38 字数 447 浏览 6 评论 0原文

是否有任何已知/简单/开源库提供 一个 javascript 函数,可以将 html 页面中显示的彩色图片切换为黑白图片,

可以在所有最常用的浏览器(IE、FireFox、Chrome)中使用?

我的意思是:

<html>
...
<img id="myPic" src="pic.jpg">
...
<script type="text/javascript">
function onEvent(){
  var pic = document.getElementById("myPic");
  magicFunctionToBlackAndWhite(pic);
}
</script>
</html>

寻找那个 ma​​gicFunctionToBlackAndWhite()

Is there any known/simple/open-source library that provide
a javascript function that will switch colored picture that is displayed in an html page into a black and white

That can be used in all the most used browsers (IE, FireFox, Chrome)?

I mean something like:

<html>
...
<img id="myPic" src="pic.jpg">
...
<script type="text/javascript">
function onEvent(){
  var pic = document.getElementById("myPic");
  magicFunctionToBlackAndWhite(pic);
}
</script>
</html>

looking for that magicFunctionToBlackAndWhite()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末蓝 2024-08-24 03:49:38

没有一种解决方案适用于所有浏览器,但您可以组合不同的解决方案:

对于 IE,使用以下 CSS:filter: Gray

许多其他浏览器支持 canvas,所以你应该能够使用这个javascript代码来实现这一点。

当然,用服务器端语言(例如 .net)制作黑白图像应该不会太麻烦,因此您始终可以使用 javascript 原则上执行如下操作:

var imgs = document.getElementsByTagName('img');
for(var i = 0; i < imgs.length; i++) {
    imgs[i].src = 'convertimage.aspx?img=' + imgs[i].src;
}

...然后有所有的魔法都发生在服务器上。

There's no one solution that works across all browsers, but you can combine different solutions:

For IE, use the following CSS: filter: Gray

A lot of other browsers supports canvas, so you should be able to use this javascript code for that.

Of course it should't be too much of a hassle to make an image b/w in a serverside language such as .net, so you could always have a javascript that in principle does something like the following:

var imgs = document.getElementsByTagName('img');
for(var i = 0; i < imgs.length; i++) {
    imgs[i].src = 'convertimage.aspx?img=' + imgs[i].src;
}

...and then have all of the magic happening on the server.

給妳壹絲溫柔 2024-08-24 03:49:38

通过使用 元素也许可以实现这一点,但我建议您自己手动或通过某种脚本制作黑白版本。相信我——这会为你省去很多麻烦。

That might be somehow possible by using the <canvas> element, but I would recommend you to do the black and white versions yourself, either manually or through some sort of script. Trust me – it'll save you a lot of trouble.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文