Convert transparent PNG to System.Drawing.Icon in code Convert transparent PNG to System.Drawing.Icon in code wpf wpf

Convert transparent PNG to System.Drawing.Icon in code


You can write

Icon.FromHandle(image.GetHIcon())

You'll need to explicitly destroy the icon when you're done with it:

[DllImport("user32.dll", CharSet = CharSet.Auto)]extern static bool DestroyIcon(IntPtr handle);DestroyIcon(newIcon.Handle);


I'm looking for this~Here is one, but not very good!

        Icon icon;        Image source = Image.FromFile(picturefile, true);        Bitmap target = new Bitmap(iconsize, iconsize,            System.Drawing.Imaging.PixelFormat.Format32bppArgb);        Graphics g = Graphics.FromImage(target);        g.DrawImage(source, 0, 0, iconsize, iconsize);        //target.Save("c:\\temp\\forest.bmp");        icon = Icon.FromHandle(target.GetHicon());        FileStream fs = File.Create(iconfile);        icon.Save(fs);        fs.Close();        icon.Dispose();        target.Dispose();        source.Dispose();