Sometimes we need to convert image formats in memory to icon, usually we should be image image = xxxx; // / hypothesis already has an image object system.io.MemoryStream mstream = new system.io.MemoryStream ); // Create memory flow image.save (mstream, system.drawing.Image.imageformat.icon); icon icon = icon.fromhandle (new bitmap (mstream) .gethicon ()); mstream.close (); but Here is an incorrect, empty object reference when image .save. So I changed the saved format as Bitmap, JPEG, etc., so there is no error (indicating that you can't save it directly as an ICON format). But in this case, the ICON will go to the transparent information in the original picture. One format test We can find that when saved as GIF format, you can still keep transparent information, haha, finally found, but here, it is worth noting that after successful acquisition, you can't use ICON construction, must To use Bitmap, otherwise it will also report. Icon icon = new icon (mstream); // This way will report an error
I hope this article is helpful for friends with the same needs, ZlyPerson @ Hotmail.com