c# - Get Icon From Application with Black BG in Mono -


i got problem when using following code icon application mono.
background color black, not expect.
there suggestion?

    [structlayout(layoutkind.sequential)]     private struct shfileinfo     {         public intptr hicon;         public intptr iicon;         public uint dwattributes;         [marshalas(unmanagedtype.byvaltstr, sizeconst = 260)]         public string szdisplayname;         [marshalas(unmanagedtype.byvaltstr, sizeconst = 80)]         public string sztypename;     };      private const uint shgfi_icon = 0x100;     private const uint shgfi_largeicon = 0x0; // 'large icon     private const uint shgfi_smallicon = 0x1; // 'small icon     [dllimport("shell32.dll")]     private static extern intptr shgetfileinfo(string pszpath, uint dwfileattributes, ref shfileinfo psfi, uint cbsizefileinfo, uint uflags);     [dllimport("shell32.dll")]     private static extern uint extracticonex(string lpszfile, int niconindex, int[] phiconlarge, int[] phiconsmall, uint nicons);     [dllimport("user32.dll")]     public static extern int destroyicon(intptr hicon);      public static bitmap getexeicon(string filename, bool smallicon)     {         shfileinfo shinfo = new shfileinfo();         uint index = 0;         uint largeicom = shgfi_largeicon;          if (smallicon)         {             largeicom = shgfi_smallicon;         }          shgetfileinfo(filename, (uint)index, ref shinfo, (uint)marshal.sizeof(shinfo), shgfi_icon | largeicom);         icon icon = (icon)system.drawing.icon.fromhandle(shinfo.hicon).clone();         destroyicon(shinfo.hicon);         return icon.tobitmap();      } 

btw, can use bitmap.fromhicon(shinfo.hicon) bitmap object, image shown rough, don't think client it.


Comments