本文介绍了在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!