Bad Quality with Icon.ExtractAssociatedIcon function

只愿长相守 提交于 2019-12-24 13:53:58

问题


I try to fetch the icon from an exe, where I have used the below snippet

 C#
 FileStream fs = new FileStream(icoFileNam, FileMode.OpenOrCreate);
 Icon ico = Icon.ExtractAssociatedIcon(exefilePath);
 ico.Save(fs);

The image saved lacks quality. I have saved the image as .ico file.

Can anyone knows how to retain the original quality of the icon present in the exefile?


回答1:


In the most common cases you can use the extracted icon bitmap data via the Icon.ToBitmap() method. You can save this image to different formats. However it is pretty hard to save the icon as "true" .ico file.

The problem is that there are no embedded encoders for icon images in .Net. So by default the result have been saved as low-color image. If this is unacceptable, the MS is recommended to save raw bitmap data as .ico manually. I suggest you use the IconLib library that already implement this task:

Icon icon = Icon.ExtractAssociatedIcon(@"C:\Windows\System32\notepad.exe");
MultiIcon mIcon = new MultiIcon();
SingleIcon sIcon = mIcon.Add("notepad");
sIcon.CreateFrom(icon.ToBitmap(), IconOutputFormat.Vista);
sIcon.Save(@"c:\notepad.ico");


来源:https://stackoverflow.com/questions/7925597/bad-quality-with-icon-extractassociatedicon-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!