I'm using this to convert the System.Drawing.Icon to a System.Drawing.Bitmap
Expand|Select|Wrap|Line Numbers
- public static System.Drawing.Bitmap ToBitmap(System.Drawing.Icon Icon)
- {
- System.IO.MemoryStream IconStream = new System.IO.MemoryStream();
- Icon.Save(IconStream);
- byte[] BitmapBytes = IconStream.ToArray();
- System.IO.MemoryStream BitmapStream = new System.IO.MemoryStream(BitmapBytes, 0, BitmapBytes.Length);
- BitmapStream.Write(BitmapBytes, 0, BitmapBytes.Length);
- return new System.Drawing.Bitmap(System.Drawing.Bitmap.FromStream(BitmapStream));
- }
But my method also causes an error after 2:34 minutes, which is on the return, which says, "Parameter is not valid."
And besides that, from what I'm aware, there's no other way of doing this, and this also causes another error after 2:34 minutes.
Expand|Select|Wrap|Line Numbers
- public static System.Drawing.Icon ToIcon(System.Drawing.Bitmap Bitmap)
- {
- return System.Drawing.Icon.FromHandle(Bitmap.GetHicon());
- }
Most of the time the GDI+ error occurs, but sometimes the other one occurs, and I'm not sure what to do about this.
Any help would really be appreciated.