Icon.ExtractAssociatedIcon函数的质量不佳 [英] Bad Quality with Icon.ExtractAssociatedIcon function
问题描述
我尝试从exe中获取图标,我在其中使用了下面的代码段
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);
保存的图像缺乏质量。我已将图像保存为.ico文件。
The image saved lacks quality. I have saved the image as .ico file.
有谁知道如何保留exefile中图标的原始质量?
Can anyone knows how to retain the original quality of the icon present in the exefile?
推荐答案
在最常见的情况下,您可以通过 Icon.ToBitmap()方法。您可以将此图像保存为不同的格式。但是很难将图标保存为true.ico文件。
问题是.Net中没有用于图标图像的嵌入式编码器。因此,默认情况下,结果已保存为低色图像。如果这是不可接受的,建议MS手动将原始位图数据保存为.ico。我建议您使用已经实现此任务的 IconLib库:
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");
这篇关于Icon.ExtractAssociatedIcon函数的质量不佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!