using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CommonFroms { public static class ImageUtils { public static System.Drawing.Bitmap ImageToBitmap(System.Drawing.Image dimg) { System.Drawing.Bitmap image; if (!(dimg is System.Drawing.Bitmap) || dimg.Palette != null) { image = new System.Drawing.Bitmap(dimg.Width, dimg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image); try { g.DrawImage( dimg, new System.Drawing.Rectangle(0, 0, dimg.Width, dimg.Height), new System.Drawing.Rectangle(0, 0, dimg.Width, dimg.Height), System.Drawing.GraphicsUnit.Pixel); } finally { g.Dispose(); } } else { image = (System.Drawing.Bitmap)dimg; } return image; } } }