Bitmap bitmap = new Bitmap(fileName);
Icon icon = Icon.FromHandle(bitmap.GetHicon());
FileStream fileStream = new FileStream("c:\\save.ico", FileMode.Create);
icon.Save(fileStream);
fileStream.Close();我用以上代码实现图片格式转换,但是转出来的图标和原来的图片颜色相差很大,各位有什么好的方法Image image = new Bitmap(fileName);
image.Save("C:\\SAVE.ICO", ImageFormat.Icon);根本不能转换成ico格式
希望各位提供写建议 100分送上
using(System.IO.FileStream fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open))
{
byte[] buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0, (int)fileStream.Length);
}using (System.IO.FileStream fs = new System.IO.FileStream(@"c:\save.ico", System.IO.FileMode.Create))
{
fs.Write(buffer, 0, buffer.Length);
}
using (System.IO.FileStream fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open))
{
byte[] buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0, (int)fileStream.Length);
}using (System.IO.FileStream fs = new System.IO.FileStream(@"c:\save.ico", System.IO.FileMode.Create))
{
fs.Write(buffer, 0, buffer.Length);
}
里面包含多个色深的不同图片用于显示在16*16 32*32 ...等等不同情况下,而且还有不同的色深所以你在生成的时候需要知道你是使用在那一种尺寸下,如果都要用到那么你就都要把不同大小的ico层的图片都添加上去,任务栏,缩略图,小图标,大图标,快捷这些他们有的调用的图片是不一样的,如果你的图片只有16*16那么他在现在到32*32大小的时候就会失真,而且这里面还设计到色深,色深和宽度的原理是一样的,系统总是会找与你需要显示的模式最匹配的ico层显示出来,否则就自动帮你修改就会导致你失真了哈,所以你的ico最好是个个层种类的图形都有,你在存放ico的时候同样也要注意这个问题,取出该对象的所有ico层并保存下来才会在不同模式下不失真参考:http://www.cnblogs.com/hoodlum1980/archive/2007/11/14/958629.html
http://ico.55.la/这个网站是可以转ICON图标的,不过不知道为什么转完背景是黑的
http://blog.csdn.net/zgke/archive/2008/11/12/3279327.aspx
ICO的操作类 具体透明你可以根据判断自己去写最后128位掩码 如果是16*16的 是64位掩码