I'm trying to rotate a System.Drawing. Icon, but first I need to convert it to a System.Drawing. Bitmap, then rotate it, and then convert it back to a System.Drawing. Icon, which is being looped, which works fine... for 2:34 minutes.
I'm using this to convert the System.Drawing. Icon to a System.Drawing. Bitmap
The reason I'm doing this is because for some reason, Icon.ToBitmap() , turns all transparency to white, my method how ever does not.
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.
After 2:34 minutes, I also get the error, "A generic error occurred in GDI+."
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.
I'm using this to convert the System.Drawing. Icon to a System.Drawing. Bitmap
Code:
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.
Code:
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.
Comment