在javascript中将png/jpg转换为.ico

编程入门 行业动态 更新时间:2024-10-25 02:22:44
本文介绍了在javascript中将png/jpg转换为.ico的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我想要一个可以从jpg/png生成 .ico 文件的工具.我使用以下代码从画布上生成了jpg:

So i want a tool that generates a .ico file from a jpg/png. I have generated the jpg from a canvas using this code:

var img = c.toDataURL("image/png"); document.write('<img src="'+img+'"/>');

从这张画布上提取的是

<canvas id="myCanvas" width="16" height="16">

问题在于;是否可以将生成的png转换为ico?

So the qustion is; is it possible to convert the generated png to a ico?

推荐答案

在Firefox中,您可以直接从画布上完成此操作:

In Firefox you can do this directly from canvas:

// Make ICO files (Firefox only) var ctx = c.getContext("2d"); ctx.arc(c.width>>1, c.height>>1, c.width>>1, 0, 6.28); ctx.fill(); c.toBlob(function(blob) { console.log(blob) }, 'image/vnd.microsoft.icon', '-moz-parse-options:format=bmp;bpp=32');

<canvas id=c width=32 height=32></canvas>

否则,要支持其他浏览器,您将必须手动构建ico文件.请参见格式说明,例如,有关如何操作的答案.

otherwise, to support other browsers you will have to build the ico file manually. See format description and for example this answer on how you can do that.

更多推荐

在javascript中将png/jpg转换为.ico

本文发布于:2023-06-16 17:31:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/747763.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   中将   javascript   png   ico

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!