Bad quality with Icon.ExtractAssociatedIcon

I am trying to extract the icon from exe where I used the snippet below

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

The saved image does not match the quality. I saved the image as a .ico file.

Does anyone know how to keep the original quality of the icon present in exefile?

+1
source share
1 answer

In the most common cases, you can use the extracted icon bitmap data using the Icon.ToBitmap () method. You can save this image in different formats. However, it is rather difficult to save the icon as a "true" .ico file .

The problem is that the built-in encoders for the icon have no image in .Net. Thus, by default, the result was saved as a low-color image. If this is not acceptable, MS is advised to save the original bitmap image data as .ico manually. I suggest you use the IconLib library that already performs 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"); 
+2
source

Source: https://habr.com/ru/post/1415501/


All Articles