本文介绍了在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
发布评论